Code Monkey home page Code Monkey logo

restapi-versioning's Introduction

Versioning in RestAPI

Types of API Versioning

• Query String Parameter Versioning.

  Ex : https://localhost:44347/api/VersioningDemo?api-version=1.0

• Media/Header API Versioning.

  Ex : https://localhost:44347/api/VersioningDemo add X-Version = 2.0 or accept = application/json;ver=2.0 in Header

• URI Versioning.

  Ex: https://localhost:44347/api/V3/VersioningDemo (v3 is the uri version)

• Deprecating Previous Versions

   API Versioning package allows us to flag APIs as deprecated. So this gives time to the client to prepare changes. Otherwise immediately deleting older APIs          could give a bad taste to clients.
   Ex [ApiVersion("1.0", Deprecated = true)] at controller level

Required Packages for API Versioning

•	Microsoft.Aspnetcore.Mvc.Versioning
•	Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer

Add extension in Configureservices in startup.cs file

      services.AddApiVersioning(version =>
      {
          version.AssumeDefaultVersionWhenUnspecified = true;
          version.DefaultApiVersion = new Microsoft.AspNetCore.Mvc.ApiVersion(1, 0);
          version.ReportApiVersions = true;
          version.ApiVersionReader = ApiVersionReader.Combine(
                          new QueryStringApiVersionReader("api-version"),
                          new HeaderApiVersionReader("X-Version"),
                          new MediaTypeApiVersionReader("ver"));
      });
      services.AddVersionedApiExplorer(options =>
      {
          options.GroupNameFormat = "'v'VVV";
          options.SubstituteApiVersionInUrl = true;
      });

restapi-versioning's People

Contributors

mvkrishnas avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.