Implementing versioning | ASP.NET Core 5 REST API Tutorial 2

preview_player
Показать описание

Hello everybody I'm Nick and in this video we will talk about the importance of versioning in our API and how we can implement it.

Don't forget to comment, like and subscribe :)

Social media:

#tutorial #rest #api
Рекомендации по теме
Комментарии
Автор

Cool Video, but i want to say, that you can set a route for a full Controler, so you can say [Route("api/v1/")] on the controler and [Route("post")] on your Action

professorchen
Автор

Your content is gold bro. I have not been coding for a while now but when i found your video it got me back. Thank you so much

ashoknaidu
Автор

Thanks from Brazil. It's very hard to found great free content like this here in Brazil. And when we look outside, it's paid and the dollar is high lol.
Thank you so much!

ruandias
Автор

Ok Nick...I thought I had you this time. (ha ha). I implemented your versioning method, and I liked it. It worked well and things looked good in Swagger. Then I came across the Microsoft Api Versioning library and looked into it. It seemed quite simple, and I was like "Hey, it's Microsoft - this has to be the 'right way' to do it" so I backed out all of my (your) code and started down that path. Holy Cow...what a waste of time. The biggest problem is that I couldn't get it to cleanly integrate with Swagger (and to be perfectly clear...Swashbuckle). I found some code to make it all work together, but even that was pretty ugly and it required extra parameters and attributes on every controller method. It was so ugly!

Anyway, your method is much simpler...cleaner...and now I have it added back into my project. Keep up the great work man!

contactestablished
Автор

Nice video. However, the font is too small to read. Kindly make it more eligible. Thanks for nice video

obinnaokafor
Автор

nice cover @Nick . I am not a big fan of URL versioning although I knew the majority of the APIs are versioned in this way. There is nothing wrong with this approach. But I prefer doing it using media type param. I still prefer to slap the route attribute value directly in my action, that way I can clearly see the endpoint that I need to hit. Although, doing it on your way could have made the code cleaner I agree on that part. Keep up the good work.

another-day-
Автор

Thank you very much Nick for the work, this is a great video series, here is my implementation of V2 based on this series (of course after creating folders for V2 and using appropriate routing). I am not an expert so any amendments are welcome.
appsettings.json : Add a new end point
"UIEndPoint": [
"v1/swagger.json",
"v2/swagger.json"
]

SwaggerOptions.cs: Change UIEndPoint's type from string to List<string>
public List<string> UIEndpoint { get; set; }

//Add a new class
to use convention based grouping
public class : IControllerModelConvention
{
public void Apply(ControllerModel controller)
{
var controllerNamespace = // e.g. "Controllers.V1"
var apiVersion =

= apiVersion;
}
}

MvcInstaller : Add convention
=>
c.Conventions.Add(new

SwaggerInstaller : Define one more document in SwaggerGen

c.SwaggerDoc("v2", new OpenApiInfo { Title = "TempIdPlus Service", Version = "v2" });

Startup.cs :
app.UseSwaggerUI(c =>
{
for (var i = 0; i < i++)
{
c.SwaggerEndpoint(swaggerOptions.UIEndpoint[i],
swaggerOptions.Description + " V" + (i + 1));
}
});

divyangutube
Автор

Great video. Would really have liked to see an implementation of V2 routes. Would you go through all the trouble of creating v2 folders for the controller and routes and then changing the url string on the Get attribute, or would you just keep everything as is and change the hard coded version string in the apiroute class to "v2"?

teriyakov
Автор

Videos are all good. But would recommend you to increase the font size of your IDE. It is too small to read sometimes.

Jashobantac
Автор

I discovered your channel today. I really like it and have already subscribed! Thank you!

BristlyBright
Автор

hi Nick, do we also version the domain classes (like 'Post' class here)?
they are not exposed to the outer world but we may need different domain objects to work with different contracts, or am I wrong?
edit: just watched chapter 4 'Creating resources using POST', still using the same domain object

easifier
Автор

If you don't mind could you please increase the font size a little? I barely can read it on my phone.

another-day-
Автор

This is really lovely. Enjoyed the tutorial

sunnyokoro
Автор

Hello Nick. For a very large project is it good to create versioning for the service layer and repository layer as well? Love your every video series.

diwaspoudel
Автор

11:00 So from my understanding, string interpolation does not work on const but old fashioned string concatenation does?

FlorinAsavei
Автор

you have to zoom the code in your videos, thanks for the content

louisovalles
Автор

Hello bro. Thank you very much. I have a doubt about how may I doing v2 kind of things. Because how can I do it without doing code duplication. can u please do a another video regarding this.

sachithureport
Автор

Why don't you just decorate the controller with the route-attribute, just like [Route("[controller]/v1")]
and then every single route just gets the last part of the route. so that
[ApiController]
[Route("[controller]/v1")]
public class WeatherForecastController : ControllerBase
{
[HttpGet]
[Route("test")]
public IEnumerable<WeatherForecast> Get()
would result in "/WeatherForecast/v1/test".

svenkicherer
Автор

Isn't there any more sofisticated way to version an api? I mean something like having an attribute over a controller action like [ApiVersions(string introducedVersion, string depricatedVersion)] that would set the valid versions range;

ferooref
Автор

All is great, but moving the route string away from controller/method will make difficult identifying the url at first look :)

stefanuzunov