Giter Site home page Giter Site logo

Comments (2)

barbosatekBU avatar barbosatekBU commented on June 11, 2024 1

Thanks, that answers my question. Closing now.

from aspnet-api-versioning.

commonsensesoftware avatar commonsensesoftware commented on June 11, 2024

Sorry to hear you're moving away from the RESTful approach, but I'm sure you have your reasons.

The combination of the QueryStringApiVersionReader and UrlSegmentApiVersionReader is the default, supported configuration as can be seen here:

get => apiVersionReader ??= Versioning.ApiVersionReader.Default;

and here:

public static IApiVersionReader Default => @default ??= Combine( new QueryStringApiVersionReader(), new UrlSegmentApiVersionReader() );

I think the misunderstanding is that you have to retain both routes. You can start with the most vanilla configuration:

builder.Services.AddApiVersioning();

Assuming you started with 1.0, then you might have something like this:

[ApiVersion(1.0)]
[ApiController]
[Route("[controller]")]
[Route("v{version:apiVersion}/[controller]")]
public class ArticlesController : ControllerBase
{
    [HttpGet]
    public IActionResult Get() => Ok();
}

[ApiVersion(2.0)]
[ApiController]
[Route("v{version:apiVersion}/articles")]
public class Articles2Controller : ControllerBase
{
    [HttpGet]
    public IActionResult Get() => Ok();
}

Without any further configuration, you'll now have the following routes:

Version URL Controller
1.0 articles?api-version=1.0 ArticlesController
1.0 v1/articles ArticlesController
2.0 articles?api-version=2.0 400
2.0 v2/articles Articles2Controller

If you have more versions, then you'll have to continue to repeat this process. Eventually, you'll be able to create single route templates for new versions once the old versions have been completely sunset. I hope that helps clear things up.

from aspnet-api-versioning.

Related Issues (20)

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.