API versioning and redirection to latest
Hi, I don't actually work on a backend at all. I'm just kinda curious how I would do this if I were to start working on a backend.
Let's say I have a
UsersController
with 3 versions so far: v1.0
, v1.1
, and v2
.
My question is; can you set up a system where sending a request to /api/v1/users
will default to the latest v1
version (v1.1
), but where you can still explicitly send a request to /api/v1.0/users
?
Can I extend that further and additionally support sending a request to /api/latest/users
(which would use v2
)?
In general, how would you tackle versioning in such a system? Do you version each individual endpoint? I guess you would version the entire controller, but only "override" the endpoints that need updating.16 Replies
I've never dealt with this myself but I found this https://weblogs.asp.net/ricardoperes/asp-net-core-api-versioning
Looks like you can do
https://github.com/dotnet/aspnet-api-versioning/wiki/API-Versioning-Options
looks like this is a good resource as well
but i don't think it really answers my core question, the redirection to the latest minor
like i think in an ideal world i would inject
IUsersService
to UsersController
, and then have V10.UsersService
, V11.UsersService
, V20.UsersService
and then some mechanism to decide the versionI think I found a good solution
wait no i don't think you would version the service, the caller of the api doesn't care about that
The version redirecting isn't the responsibility of the endpoints/controllers, so you can write a request rewriter https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-9.0#url-redirect-and-url-rewrite
URL Rewriting Middleware in ASP.NET Core
Learn about URL rewriting and redirecting with URL Rewriting Middleware in ASP.NET Core applications.
Have a middleware that says "oh, they're requesting v1? let's see what the latest minor v1 is, and then just do the ol' switcheroo in the request, before it gets to the controllers"
ohh that looks perfect
the examples do
/v1/api
. is that convention? i think i've only ever seen the other way around, /api/v1
My gut says
/api/v1
is correct, as the version is a property of the APIUnknown User•2w ago
Message Not Public
Sign In & Join Server To View
you can also look at nick chapsas' videos about versioning
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
What repo? I just saw it in the images in the link mg posted
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View

Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
this seem weird to me
if a service is able to use v2 api then why ask v1, it should be the other way
what i did for mine is that client asks service which api version it has