Buscar contenidos

jueves, 21 de junio de 2018

Provides a set of libraries which add service API versioning to ASP.NET Web API, OData with ASP.NET Web API, and ASP.NET Core.

https://www.c-sharpcorner.com/article/versioning-asp-net-core-2-0-web-api-part-one/


In this article series, we are going to explore REST API versioning best practices. By the end of the article series, you will be able to pick the best solution for your project needs.
Problem
What is one of the best ways to implement REST API versioning in ASP.NET Core?
Solution 
There are many ways to version a REST API -
  • URI-based (URL PATH SEGMENT) versioning

    GET /api/Items HTTP 1.1
    GET /api/v2/Items HTTP 1.1
  • Header-based (HTTP Header/Custom Header) versioning

    GET /api/Items HTTP 1.1
    GET /api/Items HTTP 1.1
    ApiVersion: 2
  • Query String Parameter Versioning

    /api/hi?api-version=2.0
  • Media type-based versioning

    GET /api/Items HTTP 1.1
    Accept: application/vnd.smartit.esale.webapi+json
    GET /api/Items HTTP 1.1
    Accept: application/vnd.smartit.esale webapi-v2+json
     
One of the best ways to implement the versioning in ASP.NET Core Web API is the URI-based versioning with using different namespaces on the Controllers.
  • GET /api/v1/Hi
  • GET /api/v2/Hi
In this step by step tutorial, I will demonstrate how to version a Web API in ASP.NET Core using the URI-based method with different namespaces on the Controllers.
Why you would want to choose this approach 
Let us look at the advantages and disadvantages of this approach.

PROS of URI-based API versioning
GET /api/v1/Hi
GET /api/v2/Hi
  • Most common method that is currently in use by APIs today
  • Easy to implement with the code
  • It is easy to consume
  • It allows exploring different versions with just a browser.
  • Fast performance, no overhead of search or switch statement needed.
  • Can be added to any old, not versioned or versioned REST API project
  • No extra configuration needed
  • Extremely easy to test
CONS
  • It disrupts the RESTful compliance: URIs should represent the resources and not versions (one URI: one resource/resource version)
Steps to complete REST API versioning for this example
Step 1 - Download the sample project from website
Step 2- Add API Version 1 Controller
Step 3- Add API Version 2 Controller
Step 4- Test and verify the v1 and v2 of APIs
Step 1- Download the sample project 


---------------------------------------------------------------------------------


https://github.com/Microsoft/aspnet-api-versioning

ASP.NET API Versioning

ASP.NET API versioning gives you a powerful, but easy-to-use method for adding API versioning semantics to your new and existing REST services built with ASP.NET. The API versioning extensions define simple metadata attributes and conventions that you use to describe which API versions are implemented by your services. You don't need to learn any new routing concepts or change the way you implement your services in ASP.NET today.
The default API versioning configuration is compliant with the versioning semantics outlined by the Microsoft REST Guidelines. There are also a number of customization and extension points available to support transitioning services that may not have supported API versioning in the past or supported API versioning with semantics that are different from the Microsoft REST versioning guidelines.
The supported flavors of ASP.NET are:
  • ASP.NET Web API ( nuget | quick start | samples )
    Adds service API versioning to your Web API applications
  • ASP.NET Web API and OData ( nuget | quick start | samples )
    Adds service API versioning to your Web API applications using OData v4.0
  • ASP.NET Core ( nuget | quick start | samples )
    Adds service API versioning to your ASP.NET Core applications
This is also the home of the ASP.NET API versioning API explorers that you can use to easily document your REST APIs with Swagger:
  • ASP.NET Web API Versioned API Explorer ( nuget | quick start | samples )
    Replaces the default API explorer in your Web API applications
  • ASP.NET Web API with OData API Explorer ( nuget | quick start | samples )
    Adds an API explorer to your Web API applications using OData v4.0
  • ASP.NET Core Versioned API Explorer ( nuget | quick start | samples )
    Adds additional API explorer support to your ASP.NET Core applications
You can additional find samples, documentation, and getting started instructions in the wiki.

No hay comentarios:

Publicar un comentario