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

Поделиться
HTML-код
  • Опубликовано: 26 ноя 2024

Комментарии • 81

  • @MilanJovanovicTech
    @MilanJovanovicTech  7 месяцев назад +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 7 месяцев назад +19

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад +3

      I'll talk to my editor about that 😂

    • @jeffersantosss
      @jeffersantosss 7 месяцев назад +3

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

  • @GeorgiosNtomoras
    @GeorgiosNtomoras 7 месяцев назад +3

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

  • @xavier.xiques
    @xavier.xiques 7 месяцев назад +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  7 месяцев назад +1

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

  • @joga_bonito_aro
    @joga_bonito_aro 7 месяцев назад +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)

  • @VoroninPavel
    @VoroninPavel 7 месяцев назад +3

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

  • @baranacikgoz
    @baranacikgoz 7 месяцев назад +3

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад +2

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

  • @oscarmiguelgonzalezbaute3155
    @oscarmiguelgonzalezbaute3155 4 месяца назад

    This video is pure Gold.

  • @10Totti
    @10Totti 7 месяцев назад +3

    Best Tutorial!

  • @davearkley7014
    @davearkley7014 7 месяцев назад +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 7 месяцев назад +1

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад

      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 7 месяцев назад

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

  • @rengstrom
    @rengstrom 7 месяцев назад

    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  7 месяцев назад +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 7 месяцев назад

      @@MilanJovanovicTech Alright, thanks for sharing your thoughts.

  • @milutinke
    @milutinke 7 месяцев назад

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

    • @Rob_III
      @Rob_III 7 месяцев назад

      is it really that much trouble to write in English?

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад +2

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад +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 7 месяцев назад +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 7 месяцев назад

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

  • @lyrmusica
    @lyrmusica 7 месяцев назад

    Nice video! I'm from Brazil

  • @enricoroselino7557
    @enricoroselino7557 7 месяцев назад +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 7 месяцев назад

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

    • @janjoska2549
      @janjoska2549 7 месяцев назад +1

      Just don't use it as clustered index in db

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад

      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 7 месяцев назад

      I would suggest ULID by Cysharp

    • @euler.chavez
      @euler.chavez 7 месяцев назад +2

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

  • @jimgilmartin1360
    @jimgilmartin1360 7 месяцев назад +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  7 месяцев назад

      HttpResponseMessage and parse the response...

    • @VoroninPavel
      @VoroninPavel 7 месяцев назад

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

    • @ppasieka
      @ppasieka 7 месяцев назад

      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 7 месяцев назад

      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.

  • @vgwizardx
    @vgwizardx 7 месяцев назад +1

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад

      Why?

    • @vgwizardx
      @vgwizardx 7 месяцев назад

      @@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 7 месяцев назад +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.

  • @adamchubbuck4385
    @adamchubbuck4385 7 месяцев назад

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

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад

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

  • @MikkalYT
    @MikkalYT 5 месяцев назад

    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  5 месяцев назад

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

  • @JuanOG
    @JuanOG 7 месяцев назад

    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  7 месяцев назад +1

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

    • @JuanOG
      @JuanOG 7 месяцев назад

      @@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 🤘.

  •  7 месяцев назад

    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  7 месяцев назад +1

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

  • @amierulbasyaryusoff2459
    @amierulbasyaryusoff2459 7 месяцев назад

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

  • @cuachristine
    @cuachristine 7 месяцев назад

    How much slower is the compilation because of source generation?

  • @benjsoft
    @benjsoft 7 месяцев назад

    Similar to FeignClient in Java/Springboot

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад

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

    • @benjsoft
      @benjsoft 7 месяцев назад

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

  • @oladejiakomolafe5591
    @oladejiakomolafe5591 7 месяцев назад

    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 => ruclips.net/video/WCCkEe_Hy2Y/видео.html but am using language ext by Paul Louth

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад

      Wrap it into an Either before returning?

    • @oladejiakomolafe5591
      @oladejiakomolafe5591 7 месяцев назад

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

    • @oladejiakomolafe5591
      @oladejiakomolafe5591 7 месяцев назад

      @@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 ?