Open source tools and packages for working with HTTP API

«C# ASP.NET Core ».



- «Serverless azure». 1: , serverless computing, serverless computing azure , azure function. 2: , azure storage, , ARM .






HTTP API .NET 5. HTTP API ASP.NET Core 5 Web API. HTTP API . , !





  • HTTP API ASP.NET Core 5 Web API





  • HTTP API ( )





, HTTP API 

, .NET-, HTTP API, . , ASP.NET Core Web API , , HTTP API .NET. NuGet, Visual Studio Visual Studio Code, , . Web API.





NuGet- .NET HTTP API

NuGet- HTTP API. ​​ . , .





OpenAPI

API. «» (discoverable) API , , « » (well-described). API OpenAPI ( Swagger), . . , OpenAPI -, , , , .





, OpenAPI «-» ( — , ). «», , Web API ASP.NET ASP.NET Core: NSwag Swashbuckle. ( -), HTTP API .NET.





NSwag

NSwag OpenAPI Web API NSwag.AspNetCore, :





  • C# HTTP API-, Web API OpenAPI, TypeScript-.





  • OpenAPI .NET. , , .





  • NSwagStudio, NSwag .





NuGet- NSwag Visual Studio Connected Services «OpenAPI SDK Generation», . NSwag C# API.





Swashbuckle

Swashbuckle Web API , . Swagger Codegen , API . Swashbuckle Web API, .NET 5 RC. , Visual Studio ( --no-openapi



.NET CLI dotnet new webapi



).





Swashbuckle .NET CLI Swashbuckle.CLI, OpenAPI MSBuild dotnet publish . C#, , Swashbuckle .





Microsoft.OpenAPI

NuGet- HTTP API Microsoft.OpenAPI. OpenAPI .NET Azure, :





  • Swagger OpenAPI, YAML JSON.





  • .NET OpenAPI.





  • OpenAPI.





NuGet- HTTP API .NET OpenAPI, , , Microsoft.OpenAPI. OpenAPI.





ASP.NET API Versioning

API, , , , - API, . API , , , ASP.NET API Versioning ( ) - . API Versioning 2016 , Web API.





API Versioning API , API, .





[ApiVersion("1.0")]
[ApiVersion("1.1")]
public class ShopController : ControllerBase
{
}
      
      



- , , «». , , GetProducts



GetProductsPage



, API 1.1.





[HttpGet("/products", Name = nameof(GetProducts))]
public async Task<ActionResult<IEnumerable<Product>>> GetProducts()
{
    return await Task.FromResult(Ok(StoreServices.GetProducts()));
}

[HttpGet("/products/page/{page}", Name = nameof(GetProductsPage))]
[MapToApiVersion("1.1")]
public async Task<ActionResult<IEnumerable<Product>>> GetProductsPage([FromRoute] int page = 0)
{
    var pageSize = 5;
    var productsPage = StoreServices.GetProducts().Skip(page * pageSize).Take(pageSize);
    return await Task.FromResult(Ok(productsPage));
}
      
      



API Versioning Wiki , . , API Versioning Swashbuckle, , . Startup.cs API , API Versioning, Swagger API. Swagger, , API .





Shop - 3 API 1.0. 1.1, GetProductsPage



, API 1.1.





Visual Studio Connected Services OpenAPI SDK api-version, API. API Versioning API. , API Versioning , .





// create a product
apiClient.CreateProductAsync("1.1", 
  new CreateProductRequest
  {
      Id = 1000,
      InventoryCount = 0,
      Name = "Mild Salsa"
  });

// update a product's inventory
apiClient.UpdateProductInventoryAsync(1000, "1.1", 
  new InventoryUpdateRequest
  {
      CountToAdd = 50,
      ProductId = 1000
  });
      
      



Refit

Refit - REST .NET. REST-. IContosoOnlineOrdersApiClient



, API.





public interface IContosoOnlineOrdersApiClient
{
    [Get("/products")]
    Task<IEnumerable<Product>> GetProducts();

    [Post("/products")]
    Task CreateProduct([Body] CreateProductRequest request);
}
      
      



RefitRestService



IContosoOnlineOrdersApiClient



, HttpClient



. Refit, , Refit HTTP API.





var client = RestService.For<IContosoOnlineOrdersApiClient>("http://localhost:5000");
var products = await client.GetProducts();
await client.CreateProduct(new CreateProductRequest
{
  Id = 1001,
  InventoryCount = 10,
  Name = "Taco Shells"
});
products = await client.GetProducts();
      
      



API, Refit - , . Refit HTTP API HttpClient



.





HTTP API

NuGet-, , , IDE , HTTP API.





The HttpRepl

HttpRepl .NET CLI Global , HTTP API, OpenAPI, . httprepl -o <openapi-url>



, Web API, OpenAPI, , ls



dir



, API .





HttpRepl, HttpRepl , . , HttpRepl «», «F5- HttpRepl», .





REST Client Visual Studio Code

HTTP API, Visual Studio Code. , REST Client, HTTP API IDE. .http, , REST Client «Send Request» HTTP-, .





Network Console

Microsoft Edge DevTools Network Console. Network Console Edge HTTP API . , Network Console Edge DevTools.





Network Console HTTP- «Edit and Resend».





«Edit and Resend» HTTP API Edge. .. -, HTTP API , Blazor, , API, .





OpenAPI Editor

OpenAPI , OpenAPI Visual Studio Code. OpenAPI Editor ​​. , :





  • Swagger UI ReDoc 





  • IntelliSense, JSON/YAML OpenAPI.





  • Visual Studio Code.





, HTTP API, , JSON.





, ASP.NET Core Web API

ASP.NET Web API . - , ASP.NET Web API .





API Endpoints

, API Endpoints, Web API ASP.NET Core. , HTTP API. API Endpoints , . , API Endpoints , , - , MVC Action Result ASP.NET Core.





[HttpPost("/authors")]
[SwaggerOperation(
    Summary = "Creates a new Author",
    Description = "Creates a new Author",
    OperationId = "Author.Create",
    Tags = new[] { "AuthorEndpoint" })
]
public override async Task<ActionResult<CreateAuthorResult>> HandleAsync([FromBody]CreateAuthorCommand request)
{
    var author = new Author();
    _mapper.Map(request, author);
    await _repository.AddAsync(author);

    var result = _mapper.Map<CreateAuthorResult>(author);
    return Ok(result);
}
      
      



API Endpoint Web API, Swashbuckle, NSwag Web API API Endpoints Web API, , , MVC.





Carter Project

Carter project Carter Community ASP.NET Core. Nancy project, Carter HTTP API ASP.NET Core. Carter , , API .





public class HomeModule : CarterModule
{
    public HomeModule()
    {
        Get("/", async (req, res) => await res.WriteAsync("Hello from Carter!"));
    }
}
      
      



, HTTP . OpenAPI Carter , OpenAPI. Carter Web API ASP.NET Core, Carter middleware ASP.NET Core.





API , API, . , , Web API ASP.NET ASP.NET Core, . , , - , ​​, ASP.NET .





, API. , , , , , .






«C# ASP.NET Core ».





- «Serverless azure».








All Articles