Intro to Refit REST API Client for C#

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

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

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

    Much quicker and easier solution than managing the http client on your own. Don't even want to mention unit testing. Great stuff!

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

    Refit is an awesome tool to have in my toolbox.. thank you for the awesome introductory video 😇

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

      I am glad it was helpful.

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

    This what I been looking for 🔥🔥 You rock Tim!!!

  • @steviepca
    @steviepca 11 หลายเดือนก่อน

    Great intro to Refit and thanks for the explanation with @onclick="@(e => AddGuest(item))" @35:30 mark

    • @IAmTimCorey
      @IAmTimCorey  11 หลายเดือนก่อน

      You are welcome.

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

    you are sooo good in explaiinning things!!!

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

    Awesome video, thank you. I have never heard about refit btw

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

      I'm glad I was able to introduce you to something new.

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

    Absolutely interesting and helpful tools. Thanks a lot for sharing !

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

    Excellent tool. Thanks you for another great video. Will use this in my projects.

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

    Your issue with duplicated id was caused by your count + 1. But if you had used .Max(x => x.Id) + 1 it works :) It's easy to make mistakes in recordings :)
    Great videos as usual! :)

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

      True. It was also due to trying to do it "quick and dirty" on the client-side rather than actually use a database like you normally would. That fix would be the solution for that issue, though. Good catch.

  • @vishwajeetsavandkar7617
    @vishwajeetsavandkar7617 3 หลายเดือนก่อน

    Great explanation as always

    • @IAmTimCorey
      @IAmTimCorey  3 หลายเดือนก่อน

      Thank you!

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

    Thank you Tim!
    This video tutorial help a lot make services simple

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

    Thank you for this tutorial

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

    Excellent Tutorial

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

    Great course!!!
    Thank you, Thank you, Thank you.

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

    This is awesome. Reminds me a bit of the integration wizard for Web Services that comes with VS by default. Thanks for sharing!

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

    Great unique video,. I scoured the internet to find an example of creating a web api, using another project in your solution to call the api, but most of all there was no database, just creating lists to use in the Api..

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

      Glad it was helpful!

  • @p0p0v1988
    @p0p0v1988 3 ปีที่แล้ว +15

    While Refit reduces the amount of boilerplate code you have to write when integrating with an API to a minimum, and is nice to use for smaller APIs, I think it is more useful to use code generation for the client side, based on OpenAPI/Swagger doc (either from VS or other options like NSwag Studio). That is also very helpful in updating the code when the API is updated, and there is less room for error on the client side.

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

      Ya beat me to it. Using swagger code generators is a must in big projects. I cant imagine doing all that work to get refit to work on a big project. For reference I've seen generated nswag clients that are 18k lines. While that would be smaller in refit (as you only need the interface) it is also a lot of work by hand where you only need to set up nswag once and just regen any time you (or co-workers, or vendors) make changes to the api.

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

    I'm currently watching one of your other videos on APIs and then I'll do this one! Thank you so much Tim! I've managed to connect to the server and provide my authentication but I'm not quite to getting useful information out of it yet.

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

      I am glad they have been helpful.

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

    Hi Tim, How can I set The Content-Type to application/json in Refit

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

    Excellent tuts. Keep it up 👍

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

    Thanks for the tutorial. It will be very interesting to see one about progressive web apps

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

      I will add it to the list. Thanks for the suggestion.

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

    Thanks for the video

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

    As always :-) great Video. Great work *ThumbsUp

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

    Good stuff, Thanks bro.

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

    You are amazing!

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

      I appreciate the kind words.

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

    As this amazing package encapsulates the network request, it is a little bit difficult to see the cause of problems when things do not work. Is it possible to see the content of the body in a Post request? Is there some tooling in Visual Studio that has this? I had problems because the format of a DateTime in the model class was not right for my WebAPI, which I fixed kind of just by guessing that that might be what was wrong, but it would be nice to be able to get more information for troubleshooting.

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

    Hey Corey, my dad owns a tent rental buisness (think of large circus tents) and I was thinking I want to build an utility app for android and iOS that allows us to schedule events, keep inventory, and track employee hours.
    The challenge is I only know c# and have almost zero knowledge and experience outside of simple Unity and Console apps. No web experience or anything beyond standalone desktop apps that don't do more than mess with local files or run a simple game.
    Where do i even begin? I imagine I'll need to rent a server, but i wouldn't know how to use it.

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

      @@kujingo Do you need any interns ?

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

      @@kujingo it does, but I don't have any money - and I don't think my dad is interested in investing into something like that unless it's to support me.

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

      @@kujingo ya let's chat.

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

      if it helps you, and if you already know some c#, MAUI is a very good option for mobile and also Blazor to create web applications

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

    Hi Tim! Thanks a lot. I`ve only one question: "How should I design the interface if the rest service sends an IActionResult back to caller instead of the awaited object?" Normally on an api call an IActionResult will be send back like Ok(...) or NotFound. THX. Jürgen

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

    Refit introduces too much magic that the team isn't fond of

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

      If you go to their site, you can see exactly what Refit does (and it isn’t a ton - it basically just has us inherit from a base class).

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

    In the Blazor project, how does it have access to GuestModel?

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

      Each project has its own copy of GuestModel.

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

      @@IAmTimCorey I have a question. If I´m consuming an API where I have a complex json response, how can I map my Models?

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

    Hi Tim, it's a great tutorial I have one question for you how would you unit test this? Many thanks

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

    Thank you!

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

    Big thanks for this tutorial :), easily and brilliantly explained. I have a small questions, and if in the object there are elements of the Image or byte[] type, will there be no problem with downloading such data? i.e. how could I send and retrieve images and byte[]?

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

      Usually this is done by converting the byte[] to Base64

  • @0387778o
    @0387778o 3 ปีที่แล้ว

    Hey Tim, I don't see that you have covered attributes, I don't understand how they work yet. Will you cover them in the future?

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

      Yep, they are actually high on my list to cover.

    • @0387778o
      @0387778o 3 ปีที่แล้ว

      @@IAmTimCorey can't wait, thanks.

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

    Just like 'Retrofit' in java & android. Seems nice!

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

    I LOVE this guy. Dear Tim Corey! What's the story?

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

      Thanks! As for the story, not sure what story you are wanting to hear.

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

    What if u have multiple interfaces must u add a refit client for each one

  • @anveshrocks
    @anveshrocks 9 หลายเดือนก่อน

    How does refit know the right post method on the api controller if there multiple post methods?

    • @IAmTimCorey
      @IAmTimCorey  9 หลายเดือนก่อน

      Each post method has its own URL. You can't have two POST methods use the same URL. So, you just tell Refit which URL you are calling and it does the rest.

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

    Hello, what extension show attribute description (like "path:")?

  • @the-niker
    @the-niker 3 ปีที่แล้ว +2

    Just wondering how do you react to different response status codes differently? Is this possible in Refit at all? Also is there an interface model generator from swagger.json? Hitting update on a generated NSwag client and fixing broken code is easy, going though 50+ classes looking for changes in an API you don't control is not fun. When all you get from a partner API is a swagger.json file and URL you need a generator.

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

      Why do people is so lucky to get a swagger.json file? I always get very basic documentation in custom websites or (what is worse) PDFs 😔

    • @the-niker
      @the-niker 3 ปีที่แล้ว

      @@anrodse Haha, I had to do that once, the endpoint was probably still running DOS and I had to roll the entire thing with just http calls and a lot of imagination. And every even the smallest API error invalidated future calls from the same client. Fun :D

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

      You can deal with response status codes if you use Task as return type.

    • @the-niker
      @the-niker 3 ปีที่แล้ว

      @@99MrX99 Sweet, thanks!

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

    Is this any better then using the swagger client? Whats the pros and cons to using this over swagger

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

    Thanks for explaining it so well Tim, I have recently used this library to call an API from a client(I am calling it API Client) but now when I want to test the API Client, I don't have the actual Api running with me, and would like to mock it out. but because behind the scene refit creates the httpclient factory, not sure how would I be able to mock it? any idea?

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

    How can we send Files using Refit.?

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

    Thanks I used for frontend connect to Backend with Identity4.

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

    Can you made a tutorial for Refit on SOAP ?

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

      I will add it to the list. Thanks for the suggestion.

  • @YesYou-zy7kp
    @YesYou-zy7kp 3 ปีที่แล้ว

    Have you ever considered doing a series on how to use professional products like Dev Express or Telerik?

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

      I have but I want to do it right, where it isn't just a sales tool but an actual value.

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

    In VS I noticed your screen displays Path: next it the [Get] in your interface, is that a Intelliense setup to display that?

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

      You can enable that in Visual Studio by following this video (I put it at the right time code): th-cam.com/video/f0YeVirKPfw/w-d-xo.html

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

      @@IAmTimCorey Thanks that is really helpful. And thanks for all the content. I love it.

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

    I'm not sure why. But the post request doesn't work for me I got an 400 error (.NET 6, I enabled cors on both API server and client)

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

      I'm glad you got it to work.

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

    I noticed that each of the interface methods start with Task. Is there a case where asynchronous calls would not be preferred? That is to ask, is there a reason why refit wouldn't build in the Task into their attributes?

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

    Since it's an interface you can also use it when unit testing Blazor.

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

    How does this compare to an autogenerated client from NSwag? I am currently using it in pretty much this setup, an API that I write and a Blazor client that I write.
    It works, it generates a full client including types and everything. I don't need to do anything.
    However it is not well documented and can be quite a headache to get working. Once it does, it does look strictly superior though. Especially if you have access to the API.
    Its a little confusing to newer developers. Creating a Type in the API project, building it, then its "copied" to the Client project.
    Im thinking maybe sticking to a fully blown NSwag client when I'm also the API Developer, but using this when its an external API. I tried to get NSwag to work with 2 external APIs and failed both times. This looks much easier, since its just route + type. It doesn't even need to be a swagger documented API.

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

    I prefer this way to generating the full api, why would I want 100 classes if i only need a few endpoints?

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

    Where would I do the cors in .net6 vs .net5 , it looks like there is no startup.cs now
    (rookie)

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

      This video should help: th-cam.com/video/vdhFw1VSowg/w-d-xo.html
      And don't worry about being a rookie. We all are when it comes to .NET 6 changes. None of us have even 6 months of experience with the production version of .NET 6 yet.

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

    Struggling with more complex JSON that has a child object in it, for example attributes :{call time:10,calls:20}. On a POST body. The refit doesn’t seem to handle it well, any good example of how to deal with it

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

      made some progress , but still need to figure out how to log the BODY of the POST, as something is not quite right. Logging /debugs with REFIT seems to be mystery in my searching

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

    onclick="@(e => AddGuest(item))">Add Guest
    onclick="@(e => UpdateGuest(item))">Update Guest
    onclick="@(e => DeleteGuest(item))">Delete Guest
    I follow step by step of this tutorial and
    this onclick code give me this error "Cannot convert lambda expression to type "object" because it is not a delegate type".
    any idea how to fix it? I already searching but cannot find a clue or the solution.

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

    Thanks a lot. This looks great as it simplifies things quite a bit. But I have been wondering for years... Who is Sue Storm??? ;-)

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

      One of the Fantastic Four (comic book/movie). I just use her name because it is short and easy to remember.

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

      @@IAmTimCorey I always thought she was someone of your family 😅

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

    I had a strange issue which I fixed, While creating the Interface I had copied the relative path for endpoints from swagger and build my client. But when I execute it I get 404 for the same endpoint which I can execute through swagger. The API url generated by Refit has urlencoded character "%E2%80%8B" - E2 80 8B - "ZERO WIDTH SPACE" values and API is returning 404 for it. After trying a lot, I just recreated the interface and the endpoint by typing in the url and it worked fine.. This wasted half a day of mine.

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

      I'm glad you eventually figured it out.

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

    What if ur dealing with a data context and ef multiple models not iust one interface

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

      This doesn't really have anything to do with EF. Your API access shouldn't be tied directly to your data access, so how you set up EF would not be affected by your use of Refit (and the reverse is true as well).

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

    I am second to watch this :)

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

    Good library but not complete. I expect that I don't have to manually write interface with all methods signatures for api - they must be generated automatically, like in Swagger. All I need is to generate such class and use all methods without any manual api reflection

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

    For those who are facing issues with POST and PUT requests, I solved mine by downgrading to version 5 of refit as a temporary fix. Apparently, version 6 implemented a different Json serializer causing requests with a [Body] to not work
    Another solution I've seen is to add Buffered = True into your RefitSettings, but I still couldn't get it to work

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

      Interesting. I'll look into it.

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

    Good video. But I was hopping for something else. That you will call other API's like "Giphy API" "ricky and morty API" "restcountries API" and show results on swagger.

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

      I give you the tools. You take them and create what you specifically need.

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

    gr8

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

    When you remove the standard HTTPClient factory for the Refit HTTPClient one, do you loose any functionality or flexibility for working with HTTPClient stuff directly etc, or are the effects only additive, and everything else just works the way it would have?

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

      It is the same HTTPClient, so no, you don't lose anything.

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

    your older videos had hair in the thumbnail and now its gone.

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

      Just like the hair on my head.

  • @nethaber
    @nethaber 3 ปีที่แล้ว +9

    I think that we dont need "Where" in
    guests.Where(g => g.Id == id).FirstOrDefault();
    simpler is
    guests.FirstOrDefault(g => g.Id == id);

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

      ReSharper suggest such a change as well, but if I recall correctly there were some videos on the topic and choosing .Where over passing predicate into another LINQ function may bring you performance benefits

  • @chandankumar-kr4vh
    @chandankumar-kr4vh 3 ปีที่แล้ว

    Fourth

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

    Second

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

    First

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

    Third