Elegant API Versioning in ASP.NET Core (Web API)

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 ม.ค. 2025

ความคิดเห็น • 124

  • @AnotherJanes
    @AnotherJanes 3 ปีที่แล้ว +4

    Nick, I'm a bit disappointed that I can only click on the Like button once! This is video covers a great amount of detail in a concise and well-presented way. Great Job!

  • @dracuul78
    @dracuul78 4 ปีที่แล้ว +3

    Very clear and compact demonstration of the main mechanisms. Exactly what I was looking for.

  • @JamesHunterRoss
    @JamesHunterRoss 4 ปีที่แล้ว

    All the .NET APIs I have build used ASP.NET 2.0, which is a little bit behind. We just always require version in the URL as in "v1/productByIdentity/1234" or "v2/productByIdentity/1234". This new stuff is way better, though honestly these APIs have yet to introduce a breaking change. (The video is very focused and easy to understand, so thank you!)

  • @hamednikzad911
    @hamednikzad911 4 ปีที่แล้ว

    Last night I was thinking of reading some versioning methods over the weekend. Suddenly you entered from the bright room. This is a miracle :)

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +1

      Hahaha, perfect timing! This video was long overdue.

  • @jamienordmeyer4345
    @jamienordmeyer4345 3 ปีที่แล้ว +2

    Fantastic work on this video, Nick! Very informative, and very well put together!

  • @alfkonee
    @alfkonee 4 ปีที่แล้ว +2

    Great Video on the topic have been using this package for quite a while even figured out how to handle the swagger docs but this video gave me new insights into the other versioning methods available to me thanks for the info keep them coming

    • @neighbourhater
      @neighbourhater 2 ปีที่แล้ว

      What was the trick for resolving the Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Conflicting method/path combination error?

  • @kolesplace
    @kolesplace 3 ปีที่แล้ว +1

    Thank you! I've been wondering how to version my mvc api. Now I know and it is nice that Microsoft has already done it for me. :)

  • @ghoshaninda
    @ghoshaninda 3 ปีที่แล้ว

    Thanks for making API versioning crystal clear.

  • @rbarone69
    @rbarone69 2 ปีที่แล้ว

    Wonderful!!! Great job presenting. Quick and concise

  • @TheSpruut
    @TheSpruut 3 ปีที่แล้ว

    Wonderful video Nick, can't wait to use these methods to implement versioning in my own work. Thanks!

  • @kennethgrande5749
    @kennethgrande5749 4 ปีที่แล้ว

    Great introduction Nick! One side note: Don't forget to decorate your Controller with [ApiController], i was scratching my head for a while trying to figure out why the controller didn't pick up the configuration :)

    • @commonsensesoftware
      @commonsensesoftware 2 ปีที่แล้ว

      A little known feature is that you can also target the entire assembly with [assembly: ApiController]. This will make all controllers in the project API controllers.
      The reason this is required is be cause a controller is just a controller. Some people mix UI controllers and API controllers in the same project. ApiControllerAttribute provides a simple and clear way to disambiguate the two.

  • @IssaFram
    @IssaFram 4 ปีที่แล้ว +2

    Good video but I wouldn't recommend using query strings or request headers for the version. Keeping it in the route is the best way to go imo. Makes it very explicit and required. This ensures that the client know what they are using.

  • @LonliLokli
    @LonliLokli 4 ปีที่แล้ว

    Great and short video, covering all major usecases

  •  2 ปีที่แล้ว

    Gràcies!

  • @akshaytrimbake4812
    @akshaytrimbake4812 3 ปีที่แล้ว

    This is sweet, small and crisp. Thanks 😊

  • @Punkologist
    @Punkologist 2 ปีที่แล้ว

    amazing video. I will absolutely be putting this to use

  • @vasilkostov2673
    @vasilkostov2673 3 ปีที่แล้ว

    Great video! Just what I've been looking for :)

  • @grtuser
    @grtuser 4 ปีที่แล้ว

    Your all videos are so informative and well prepared. Finally you look like titanic actor :)

  • @nadeemlari
    @nadeemlari 3 ปีที่แล้ว

    Awesome, very helpful nice way to maintain API version

  • @TheVincent0268
    @TheVincent0268 4 ปีที่แล้ว +10

    is it possible to make the url-variant (api/v2/products) optional, just as the querystring and header variant are also optional? Or is it compulsory to use the /v in the url once that is defined in the routing?

    • @commonsensesoftware
      @commonsensesoftware 2 ปีที่แล้ว +2

      Unfortunately, that is not possible. It is no different than if you had "order/{id}/items". AssumeDefaultVersionWhenUnspecified, therefore, will not likely not do what you want. In order to make that work, you would need to use multiple route templates. For example:
      [Route("[controller]")]
      [Route("v{version:apiVersion}/[controller]")]
      Now the route without the API version route constraint will assume the default version.

  • @panagakis79
    @panagakis79 3 ปีที่แล้ว

    Great content as always man! Helped me a lot. thanks!

  • @Azcane
    @Azcane 3 ปีที่แล้ว

    Great video and overview.
    Would have been great if you put the link to the package in the video description though.

  • @SimoLPers
    @SimoLPers 3 ปีที่แล้ว +1

    Instead of using typeof(Contoller).GetMethod(...) In the last part of the video, you can use an expression, so it is at least a bit cleaner

  • @javierpetrozzi
    @javierpetrozzi 3 ปีที่แล้ว

    Thank you Nick, very good explanation!

  • @zc2012
    @zc2012 4 ปีที่แล้ว

    Really useful library. Great job!

  • @FranchevandenBerg
    @FranchevandenBerg 4 ปีที่แล้ว

    Really Awesome Video! Thanks for sharing!
    I booked marked this video!

  • @Computerix
    @Computerix 4 ปีที่แล้ว

    Awesome video, subscribed! And saved it to a playlist so I can come back to it in the future when dealing with different versions :)

  • @saurabhchauhan232
    @saurabhchauhan232 4 ปีที่แล้ว

    Thank you for coming with crystal clear explanation.

  • @UzairAli001
    @UzairAli001 4 ปีที่แล้ว +1

    Really nice introduction tutorial.

  • @SibTiger33
    @SibTiger33 4 ปีที่แล้ว

    Wow this is really impressive I'm going to test this out. Thanks 👍👍

  • @joetrueman3555
    @joetrueman3555 4 ปีที่แล้ว

    Great, and timely video, Nick! Thank you. Btw “2 dots” = ‘colon’ :)

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +2

      I think I was born with the defect to mix colon and semicolon and also mix square brackets with curly braces 😂

    • @mhDuke
      @mhDuke 4 ปีที่แล้ว

      @@nickchapsas curly brackets are totally fine as well

  • @lahcencodery
    @lahcencodery 4 ปีที่แล้ว

    Just in time! thanks for sharing

  • @mhDuke
    @mhDuke 4 ปีที่แล้ว +1

    Nick, you promised a while a go you will share with us the way you adopt to handle core domain return types and error handling. some people use exceptions, others use the Either and the likes. When will you fulfill?

  • @dastrn
    @dastrn 4 ปีที่แล้ว

    Excellent video. Thanks for this.

  • @stevemcqueen2887
    @stevemcqueen2887 ปีที่แล้ว

    The v1 and v2 folders seem like a much better idea mate 🤣

  • @joelinherts
    @joelinherts 3 ปีที่แล้ว

    Excellent video. Thank you sir.

  • @bahtiyarozdere9303
    @bahtiyarozdere9303 3 ปีที่แล้ว

    Thank you for very usefull tip! As always.

  • @bhushangawale3252
    @bhushangawale3252 3 ปีที่แล้ว +2

    As usual, an informational video and thanks for sharing it. Any specific settings for Swagger UI to start showing version info?

    • @belugaaa6649
      @belugaaa6649 3 ปีที่แล้ว +2

      exactly i am facing an exception when using swagger UI> any comments @nick chapsas?

    • @neighbourhater
      @neighbourhater 2 ปีที่แล้ว

      Same, getting an exception when having a v1 and a v2 method with the same route:
      Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Conflicting method/path combination

  • @niroshanmanoharan4295
    @niroshanmanoharan4295 4 ปีที่แล้ว

    Great informative video. Thank you!

  • @haraldkofler1170
    @haraldkofler1170 4 ปีที่แล้ว

    Really good Tutorial ob this topic!

  • @Cralis1
    @Cralis1 3 ปีที่แล้ว

    Great video again, Nick.

  • @hassanOnYoutube
    @hassanOnYoutube 4 ปีที่แล้ว

    Thanks for the video ! Love it !

  • @sivakumarsubramaniam6594
    @sivakumarsubramaniam6594 3 ปีที่แล้ว

    Insightful, great understands

  • @syedasim6813
    @syedasim6813 3 ปีที่แล้ว

    very well explained. thanks

  • @dambros
    @dambros 3 ปีที่แล้ว

    What shortcut did you press at 3:45 for the "options" be autocompleted?

    • @nickchapsas
      @nickchapsas  3 ปีที่แล้ว

      That would be Ctrl + Space in my Rider config

  • @OlegKosmakov
    @OlegKosmakov 4 ปีที่แล้ว +5

    Great video. I wish I had a project where it would be used, sigh :(

  • @ibnfpv
    @ibnfpv 4 ปีที่แล้ว +1

    Great tutorial , is there a best practice to include the version from assembly version number dynamically? and not hardcoded
    Like if I increase the api version this is the default version , and only for deprecated mention the version it was referring to

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +5

      I think you can get around it if you properly version the assembly but in my opinion since versioning is such a sensitive thing that can break consumers, I would want to have it fully controlled

  • @TeamCykelhold
    @TeamCykelhold 3 ปีที่แล้ว

    I am adopting similar ways in my azure functions api, going to newer versions without braking anything. There however I just create a new route for V2 and and another for V1. V1 points to one without versioning, and when I am ready I can just switch it to makes the one without V2 in url route to the V2 (making it default).

  • @vredurs
    @vredurs 3 ปีที่แล้ว

    Great video, thanks!

  • @franciscovilches6839
    @franciscovilches6839 3 ปีที่แล้ว

    thanks once again! great content

  • @ossamaabdallah88
    @ossamaabdallah88 4 ปีที่แล้ว

    Thanks for sharing this information

  • @TheJessejunior
    @TheJessejunior 3 ปีที่แล้ว

    this was great!! thanks!!!

  • @mihaimyh
    @mihaimyh 4 ปีที่แล้ว +1

    Great video, I knew about this library but never went to find more about it. What is your process to learn about new libraries, do you read official docs and test it?

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +1

      I will usually scan Microsoft repos for the helper libraries that they make. They follow specific naming patterns and they are easy to find. Sometimes they are not documented though to it’s either reading blogs or playing around with them myself.

  • @enzosambucetti6571
    @enzosambucetti6571 ปีที่แล้ว

    Great Video! What about with Azure Functions and versioning?

  • @limroto
    @limroto 4 ปีที่แล้ว +1

    Great video.
    Question: if I have 3+ different endpoints, and each have a different version (1.0, 2.0 and 3.0) - can I tell the options to take the "highest" version?

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว

      Do you mean as the default version?

    • @limroto
      @limroto 4 ปีที่แล้ว

      @@nickchapsas Yes.

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +4

      @@limroto So you can but changing the default version once an API is live is dangerous since you can break existing consumers that didn't expect the change. If it is properly communicated then yeah you can with the default version property

  • @prafulsinghvit
    @prafulsinghvit 3 ปีที่แล้ว

    Just wondering if you have a complete net core API tutorial series... would be interested in that.
    thanks for this, btw.

    • @nickchapsas
      @nickchapsas  3 ปีที่แล้ว

      I actually do but it's for REST APIs

  • @greeksinmars
    @greeksinmars ปีที่แล้ว

    This is why i follow you....

  • @spquest2386
    @spquest2386 2 ปีที่แล้ว

    Can you also make a video on how to add swagger api definitions for different versions? Swagger UI stopped working after I added API versioning.

  • @hexoter
    @hexoter ปีที่แล้ว

    Great content❤

  • @kristianaranda
    @kristianaranda 3 ปีที่แล้ว

    Great video!

  • @noblenetdk
    @noblenetdk 3 ปีที่แล้ว

    Could you show how to combine swagger and versioning

  • @m3xpl4y
    @m3xpl4y 3 ปีที่แล้ว

    Thank you @Nick

  • @dyakobaram
    @dyakobaram 4 ปีที่แล้ว +6

    does build in swagger in .net 5 auto-update with it?

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +25

      So I intentionally left that outside to not inflate the video in case someone isn't using Swagger. I haven't found a way to make it auto update but I have found a way to make it simpler to update. I am still looking into the "best" way to do it and one I have it will make a followup video

    • @dyakobaram
      @dyakobaram 4 ปีที่แล้ว

      @@nickchapsas thank you can't wait for your new videos :)

    • @IssaFram
      @IssaFram 4 ปีที่แล้ว +1

      @@nickchapsas Swashbuckle can do this all for you. Just need to setup the swagger gen options.

    • @MrLuccasMF
      @MrLuccasMF 3 ปีที่แล้ว

      @@IssaFram do you know how to configure the options to autoupdate the versions ?

  • @shahzadazzam
    @shahzadazzam 2 ปีที่แล้ว

    That's a good one 👍

  • @clearlyunwell
    @clearlyunwell 3 ปีที่แล้ว

    Very useful!

  • @altravels7426
    @altravels7426 3 ปีที่แล้ว

    Sick vid bro

  • @ShubhamSharma-eo4oq
    @ShubhamSharma-eo4oq ปีที่แล้ว

    what if want use "api/v2.1/product" than what changes has to be made

  • @aditisen20
    @aditisen20 2 ปีที่แล้ว

    well explained!

  • @gkmishra2009
    @gkmishra2009 4 ปีที่แล้ว

    In One project how we cosume wcf and web api both. can you help with web.config how we write for it

  • @AshleyMathClass
    @AshleyMathClass 3 ปีที่แล้ว

    Could you please refer me to a video where you use multiple controllers like you showed at the start(v1 and v2 folders)?

  • @chrislunar8214
    @chrislunar8214 2 ปีที่แล้ว

    Excellent video you covered everything except configuration of swagger for versioning. For dotNet Core 6 I can't find this method AddVersionedApiExplorer in Asp.Versioning.Mvc.ApiExplorer to be able to configure swagger for versioning. Do you know how this is done?

    • @commonsensesoftware
      @commonsensesoftware 2 ปีที่แล้ว

      Things changed in .NET 6. You want to be using the "Asp.Versioning.Mvc.ApiExplorer" package. That will include all the transitive dependencies you need. The configuration has changed a little:
      services.AddApiVersioning() // support Minimal APIs
      .AddMvc() // add MVC core (e.g. controllers)
      .AddApiExplorer(); // add API explorer extensions

  • @pdevito
    @pdevito 4 ปีที่แล้ว +2

    nice intro! any thoughts on integrating api versioning when you have a gateway in ocelot, envoy, AAG, aws gateway, etc.?

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +1

      As long as your versioning strategy is supported by the gateway I can't see how it would be an issue

    • @pdevito
      @pdevito 4 ปีที่แล้ว

      @@nickchapsas this is on my todo list for later in the year, but what I’m guessing this looks like in practice (and what I assume you mean but supported in the gateway) is more explicitly calling out the versions in routes where needed. Don’t think I’ll be able to leverage it as streamlined on the gateway end. Is what it is, just wasn’t sure if I was missing something.

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +2

      Obviously you could use a traffic manager to reroute requests based on header values or url routes to different versions or clusters but I don’t have the full picture of your system to know exactly what to recommend

  • @oi_faen
    @oi_faen 4 ปีที่แล้ว

    do you have some nice distributed lock examples?

  • @priyanshu4016
    @priyanshu4016 3 ปีที่แล้ว

    Great video

  • @80mirror
    @80mirror 4 ปีที่แล้ว

    Is there support for default handling of the route versioning option. So the client won't have to put version in the address for 1.0 but for 2.0 the address will be v2/controller...?

    • @commonsensesoftware
      @commonsensesoftware 2 ปีที่แล้ว

      The short answer is - no. In the same way that "order/{id}/items" will not route without an "{id}". The only way you can make this this work is if you register the default route twice. For example:
      [Route("[controller]"])
      [Route("v{version:apiVersion}/[controller]")]
      If AssumeDefaultVersionWhenUnspecified=true, then "/controller" can now be matched against DefaultApiVersion.

  • @JosephHerrington
    @JosephHerrington 4 ปีที่แล้ว

    Good job!

  • @AbZen7
    @AbZen7 4 ปีที่แล้ว

    What IDE are yyou using?

  • @jamesherrero7334
    @jamesherrero7334 4 ปีที่แล้ว

    What ide are you using? it ran so fast when you hit run!
    Also side note perchance how did you get https running locally?

    • @lorenzogomezmolina2086
      @lorenzogomezmolina2086 4 ปีที่แล้ว

      I think it is this one www.jetbrains.com/rider/

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว

      Hey! As Lorenzo said I'm using Jetbrains Rider, which is a lot faster than VS. https run locally natively. Rider gives you a promt to intall the certificate and it just works.

  • @MdArefinReflex
    @MdArefinReflex 2 ปีที่แล้ว

    How to handle versionless calls to default version for url routing versioning

    • @commonsensesoftware
      @commonsensesoftware 2 ปีที่แล้ว

      There isn't really a concept of "versionless"; however, you can have a version-neutral API. This means it accepts any implemented API, including none at all. You can use the [ApiVersionNeutral] attribute or .IsApiVersionNeutral() convention.

  • @bonaoenchelcha
    @bonaoenchelcha 4 ปีที่แล้ว

    Thanks!!

  • @JM-ly1vc
    @JM-ly1vc 2 ปีที่แล้ว

    Thank You

  • @dskunu
    @dskunu 3 ปีที่แล้ว

    All your videos, text are not visible in visual studio. can you somehow zoom into the screen while recroding? like how @IAmTimCorey does.

    • @nickchapsas
      @nickchapsas  3 ปีที่แล้ว

      Watch the video on fullscreen. Any bigger and it would be impossible for me to actually write the code that I'm showing

  • @piterbots84
    @piterbots84 2 ปีที่แล้ว

    amazing

  • @itsrahimuddinkhan
    @itsrahimuddinkhan 4 ปีที่แล้ว

    Awesome.

  • @noblenetdk
    @noblenetdk 3 ปีที่แล้ว

    Contracts? The way you mention them makes me think you've talked about it before - which video?

  • @pavlokysylevych5725
    @pavlokysylevych5725 4 ปีที่แล้ว

    How come that you have v1 deprecated but you still have an access to it?

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +2

      Deprecated doesn't mean it's inactive. It's an indication that it will be removed and it would guide the user to seek documentaiton for the new v2 version and the cutoff or end of life of the currect deprecated version.

    • @pavlokysylevych5725
      @pavlokysylevych5725 4 ปีที่แล้ว

      @@nickchapsas got it! Thanks for the explanation.

  • @Thomasilliet
    @Thomasilliet 3 ปีที่แล้ว

    Api versioning is not ready for odata controllers, because this feature do not support same name of actions or function on all apis ... actually this feature is not ready to production....

  • @dharmeshsharma
    @dharmeshsharma 3 ปีที่แล้ว

    Copy of method is not solution for frequently releases for minor changes or Update.

  • @nikolaiv386
    @nikolaiv386 ปีที่แล้ว

    Changing the route is a breaking change :(

  • @avriunity494
    @avriunity494 3 ปีที่แล้ว

    How is that "Elegant" when you need to duplicate all your code (repositories models etc..)

    • @nickchapsas
      @nickchapsas  3 ปีที่แล้ว

      You don't. You can handle all that in the mapping layer.

  • @TheKhanAu
    @TheKhanAu 3 ปีที่แล้ว

    Й
    Ф
    Ф