@manhng

Welcome to my blog!

Consume RESTful API in C#

November 3, 2019 16:19

Create a test RESTful WEB API service using ASP.NET Core 2.1 (edit)

Create a test RESTful WEB API service using ASP.NET Core 2.1

Part 1. Creating a test RESTful WEB API application

https://www.codeproject.com/Articles/1260600/Speed-up-ASP-NET-Core-WEB-API-application-Part-1

Part 2. Using various approaches to increase the application's productivity

https://www.codeproject.com/Articles/1261345/Speed-up-ASP-NET-Core-WEB-API-application-Part-2

Part 3. Deep refactoring and refinement of ASP.NET Core WEB API application code

https://www.codeproject.com/Articles/4049519/Speed-up-ASP-NET-Core-WEB-API-application-Part-3

Repositories

using SpeedUpCoreAPIExample.Models;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SpeedUpCoreAPIExample.Repositories
{
    public interface IProductsRepository
    {
        Task<IEnumerable> GetAllProductsAsync();
        Task GetProductAsync(int productId);
        Task<IEnumerable> FindProductsAsync(string sku);
        Task DeleteProductAsync(int productId);
    }
}
using SpeedUpCoreAPIExample.Models;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SpeedUpCoreAPIExample.Interfaces
{
    public interface IPricesRepository
    {
        Task<IEnumerable> GetPricesAsync(int productId);
    }
}

Repositories Implementation

using Microsoft.EntityFrameworkCore;
using SpeedUpCoreAPIExample.Contexts;
using SpeedUpCoreAPIExample.Interfaces;
using SpeedUpCoreAPIExample.Models;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SpeedUpCoreAPIExample.Repositories
{
    public class ProductsRepository : IProductsRepository
    {
        private readonly DefaultContext _context;

        public ProductsRepository(DefaultContext context)
        {
            _context = context;
        }

        public async Task<IEnumerable> GetAllProductsAsync()
        {
            return await _context.Products.ToListAsync();
        }

API Versioning in ASP.NET Core Web API 2.1

https://dzone.com/articles/api-versioning-in-net-core

API & Client : AutoMapper + Cross-Origin Resource Sharing (CORS) + API Versioning + Swagger

https://blog.ng-book.com/getting-started-with-angular-and-asp-net-core/

A Few Great Ways to Consume RESTful API in C#

There are several ways to consume a RESTful API in C#:

https://code-maze.com/different-ways-consume-restful-api-csharp/

https://github.com/CodeMazeBlog/ConsumeRestfulApisExamples

Categories

Recent posts