The Best .NET REST API Client You Didn't Know About

Поділитися
Вставка
  • Опубліковано 23 гру 2024

КОМЕНТАРІ •

  • @MilanJovanovicTech
    @MilanJovanovicTech  8 місяців тому +1

    Get the source code for this video for FREE → the-dotnet-weekly.ck.page/refit
    Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
    Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt

  • @ahmedrizk106
    @ahmedrizk106 8 місяців тому +19

    that bright screen warning 0.1s before the bright screen is a scam 😂 ... Great video as always Milan ❤👏

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому +3

      I'll talk to my editor about that 😂

    • @jeffersantosss
      @jeffersantosss 8 місяців тому +3

      @@MilanJovanovicTech, you can turn swagger theme to the dark mode for the video, customizing the swagger UI css.. haha

  • @GeorgiosNtomoras
    @GeorgiosNtomoras 8 місяців тому +3

    Loved the way you compare the traditional with the modern way of doing things. Thank you for sharing this

  • @xavier.xiques
    @xavier.xiques 8 місяців тому +1

    The Refit implementation is the same as used in FeignClients, in Spring Boot applications for example.
    Love it.
    Thanks for the video Milan.

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому +1

      A lot of .NET libraries were inspired by existing Java libraries

  • @baranacikgoz
    @baranacikgoz 8 місяців тому +3

    Great video. But I wouldn't use an extra dependency just to shorten my code 2 lines. Thanks for sharing alternatives

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому +2

      Fair enough, that's your decision to make. But do consider how this scales as the number of endpoints increases.

  • @VoroninPavel
    @VoroninPavel 8 місяців тому +3

    Couple of downsides: Refit currently does not support streaming, and it's not AOT friendly. Both issues are tracked on github.

  • @davearkley7014
    @davearkley7014 8 місяців тому +3

    Are you aware of a package which can generate a Refit client form an OpenApi spec (yaml - v3.0.1)?

  • @Rob_III
    @Rob_III 8 місяців тому +1

    What do you all use for a (thread-safe) token delegating handler which refreshes the token when expires?

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому

      Would all requests share the same token, or do we need to make sure we use the _correct_ token for each request?

    • @Rob_III
      @Rob_III 8 місяців тому

      @@MilanJovanovicTech All request would share the same token. I have implemented my own, but I'm curious if there are (more battle-tested) solutions.

  • @jimgilmartin1360
    @jimgilmartin1360 8 місяців тому +1

    What about error handling using refit? If the api returns either a DTO on success and a different, error DTO on failure, along with the appropriate status code, what does that look like? In general I like returning error objects along with a 4xx status code, but handling them feels like a lot of work.

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому

      HttpResponseMessage and parse the response...

    • @VoroninPavel
      @VoroninPavel 8 місяців тому

      @@MilanJovanovicTech or just catch an exception which also contains the content and can be deserialized as required type.

    • @ppasieka
      @ppasieka 8 місяців тому

      Or return ApiResponse. It will have the parsed content alongside with all the headers. Just don't get crazy and do not make this type lurking around through all the layers in your application.

    • @DiegoModoloRibeiro
      @DiegoModoloRibeiro 8 місяців тому

      The perfect scenario would be Refit allow something like Task GetAsync(), and deserialize accordingly. I don't feel comfortable returning 200 for errors so Refit will be able to serialize the response.

  • @rengstrom
    @rengstrom 8 місяців тому

    Disclaimer, watched the video without sound so maybe you covered this. :P But in the context of clean architecture, in which layer would you put the interface? Seems to me like I would need to have it in the infrastructure layer because I don't want to have models in my domain that is tightly coupled to an external dependency. So I'd need some adapter that uses this interface, fetches models and converts it into som dto in my domain.

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому +1

      You can either sacrifice purity, and have the interface in Application. Or create another abstraction that will be implemented using Refit in Infrastructure.

    • @rengstrom
      @rengstrom 8 місяців тому

      @@MilanJovanovicTech Alright, thanks for sharing your thoughts.

  • @enricoroselino7557
    @enricoroselino7557 8 місяців тому +2

    a bit OOT but github use int for user id, then what do you think about userid better use int or uuid (or some sort) ? or its depend on the usage ?

    • @md.redwanhossain6288
      @md.redwanhossain6288 8 місяців тому

      Most of the tech giants use int, it has significantly better performance than uuid.

    • @janjoska2549
      @janjoska2549 8 місяців тому +1

      Just don't use it as clustered index in db

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому

      At GitHub's scale using a UUID probably has a performance impact, so that's another reason. Most of the time I'm not concerned with that. An interesting alternative if you want sortable (at creation) IDs is ULID

    • @joga_bonito_aro
      @joga_bonito_aro 8 місяців тому

      I would suggest ULID by Cysharp

    • @euler.chavez
      @euler.chavez 8 місяців тому +2

      @@MilanJovanovicTech It would be nice to have a video discussing the following topics: UUID, GUID, ULID, Snowflake ID (probably more).

  • @joga_bonito_aro
    @joga_bonito_aro 8 місяців тому +5

    I said, ooh, I'm blinded by the lights
    No, I can't sleep until I refactor the http
    I said, ooh, I'm drowning in the lines
    Oh, when I'm like this, refit is the one I trust
    (Hey, hey, hey)

  • @10Totti
    @10Totti 8 місяців тому +3

    Best Tutorial!

  • @oscarmiguelgonzalezbaute3155
    @oscarmiguelgonzalezbaute3155 4 місяці тому

    This video is pure Gold.

  • @MikkalYT
    @MikkalYT 6 місяців тому

    Any ideas how to setup this with Autofac DI container? Searched web but I cannot see any sdk from refit to deal with, so probably some custom setup required

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 місяців тому

      Shouldn't it just work? Not sure which part is missing with Autofac?

  • @JuanOG
    @JuanOG 8 місяців тому

    How would you implement caching for certain api endpoints in refit. I haven't seen any options for this. Best case scenario is that there is some attribute which will allow the refit client to be source generated with caching. But unfortunately that doesn't seem to be the case.

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому +1

      A delegating handler that caches based on the URL params could get the job done

    • @JuanOG
      @JuanOG 8 місяців тому

      @@MilanJovanovicTech yes that would work. But if it was an attribute of some sort, it would have been more clean and scalable. Great alternative though 🤘.

  • @adamchubbuck4385
    @adamchubbuck4385 8 місяців тому

    @MilanJovanovicTech, a bit off topic, but are there any reasonably decent alternatives to Swagger’s UI?

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому

      Not that I know, but I haven't really looked for any

  • @amierulbasyaryusoff2459
    @amierulbasyaryusoff2459 8 місяців тому

    Really nice library. Not yet try it. But, can it also handle http status also?

  • @cuachristine
    @cuachristine 8 місяців тому

    How much slower is the compilation because of source generation?

  • @vgwizardx
    @vgwizardx 8 місяців тому +1

    Maybe for personal projects. But I couldn't see myself using this for production work projects.

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому

      Why?

    • @vgwizardx
      @vgwizardx 8 місяців тому

      @@MilanJovanovicTech I have been burned by thrid-party libraries in the past (looking at you restsharp). Maybe refit is better but some things I just prefer built-in libraries. I also hate when a feature I'm used to isn't available and now I have to mix and match libraries to get what I want. I'm not trying to say that's the case with refit but my experience in the past.

    • @vgwizardx
      @vgwizardx 8 місяців тому +1

      I have been burned by third party libraries in the past. You also have to get everyone on board. So I try to use built-in libraries as often as possible.

  • @lyrmusica
    @lyrmusica 8 місяців тому

    Nice video! I'm from Brazil

  • @milutinke
    @milutinke 8 місяців тому

    Ћао, одлична библиотека и видео.
    Имам предлог, а то је да направиш додатни видео да покажеш како да се са Refit-ом и на пример са Polly-ем постигне поузданост, на пример ако неки захтев пукне, па да га пошаље поново.

    • @Rob_III
      @Rob_III 8 місяців тому

      is it really that much trouble to write in English?

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому +2

      Polly има готову библиотеку коју можемо да углавимо овде, можда је више тема за блог него за видео.

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому +1

      @Rob_III What's wrong with some Serbian? 😁 He was suggesting to make a video about Polly and adding resiliency to HTTP client requests.

    • @Rob_III
      @Rob_III 8 місяців тому +4

      @@MilanJovanovicTech There's nothing wrong with Serbian. My native language is Dutch. I just don't post in Dutch because most people don't understand it and it creates a little "just for us -speakers"-circle-vibe. That's why I wondered why it was too much trouble to write in English.

    • @vgwizardx
      @vgwizardx 8 місяців тому

      @@Rob_III If you don't speak english or understand it. You might not trust translators. Which I can completely understand.

  •  8 місяців тому

    1) the Async suffix is moreorless obsolete now ... there were reasons to name the methods like that, but you don't have to do that anymore.
    2) you forgot cancellationtokens ...

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому +1

      1) Don't care, I still like using it as a convention. Nothing wrong with that.
      2) Fair point. 👍

  • @benjsoft
    @benjsoft 8 місяців тому

    Similar to FeignClient in Java/Springboot

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому

      That's cool, I like learning about Java libraries that do the same thing

    • @benjsoft
      @benjsoft 8 місяців тому

      @@MilanJovanovicTech yes that's why Refit is familiar :D Thanks for this interesting library :D

  • @oladejiakomolafe5591
    @oladejiakomolafe5591 8 місяців тому

    Thanks for this Milan , Please how can I use Refit with a controller that returns an Either result type ( this is similar to the Result pattern you explained here => ua-cam.com/video/WCCkEe_Hy2Y/v-deo.html but am using language ext by Paul Louth

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому

      Wrap it into an Either before returning?

    • @oladejiakomolafe5591
      @oladejiakomolafe5591 8 місяців тому

      @@MilanJovanovicTech Exactly what I did but Refit is throwing deserialisation error

    • @oladejiakomolafe5591
      @oladejiakomolafe5591 8 місяців тому

      @@MilanJovanovicTech I want to use refit to generate an sdk but am getting the error => : The JSON value could not be converted to LanguageExt.Either`2
      this is my controller
      [HttpGet(template: DocumentVersionManagerAPIEndPoints.Model.Get, Name =
      DocumentVersionManagerAPIEndPoints.Model.Get)]
      public Task Get(CancellationToken cToken) => _sender.Send(new GetAllModelQuery(), cToken).ToActionResult();
      This is my refit interface
      [Get("/api/v1/Models")]
      Task Get(CancellationToken cToken);
      I also tried using [Get("/api/v1/Models")]
      Task Get(CancellationToken cToken);
      in both cases I got
      An error occured deserializing the response.
      Please I need help is there a way I can correctly have Either Result in my controller return type and still Use Refit for my SDK development ?