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
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)
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.
You can either sacrifice purity, and have the interface in Application. Or create another abstraction that will be implemented using Refit in Infrastructure.
Ћао, одлична библиотека и видео. Имам предлог, а то је да направиш додатни видео да покажеш како да се са Refit-ом и на пример са Polly-ем постигне поузданост, на пример ако неки захтев пукне, па да га пошаље поново.
@@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.
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
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.
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.
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.
@@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.
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.
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
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 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 ...
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 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 ?
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
May be i lost newsletter message, but i can`t find post for this video with sources....
that bright screen warning 0.1s before the bright screen is a scam 😂 ... Great video as always Milan ❤👏
I'll talk to my editor about that 😂
@@MilanJovanovicTech, you can turn swagger theme to the dark mode for the video, customizing the swagger UI css.. haha
Loved the way you compare the traditional with the modern way of doing things. Thank you for sharing this
Glad you liked it!
What's not modern with either of these two solutions?
The Refit implementation is the same as used in FeignClients, in Spring Boot applications for example.
Love it.
Thanks for the video Milan.
A lot of .NET libraries were inspired by existing Java libraries
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)
Nice one 🏆
Couple of downsides: Refit currently does not support streaming, and it's not AOT friendly. Both issues are tracked on github.
Good points!
Great video. But I wouldn't use an extra dependency just to shorten my code 2 lines. Thanks for sharing alternatives
Fair enough, that's your decision to make. But do consider how this scales as the number of endpoints increases.
This video is pure Gold.
Thanks a lot! :)
Best Tutorial!
Glad you think so!
Are you aware of a package which can generate a Refit client form an OpenApi spec (yaml - v3.0.1)?
I'm not aware
Refitter
@@Rob_III Thanks Rob, looks interesting
What do you all use for a (thread-safe) token delegating handler which refreshes the token when expires?
Would all requests share the same token, or do we need to make sure we use the _correct_ token for each request?
@@MilanJovanovicTech All request would share the same token. I have implemented my own, but I'm curious if there are (more battle-tested) solutions.
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.
You can either sacrifice purity, and have the interface in Application. Or create another abstraction that will be implemented using Refit in Infrastructure.
@@MilanJovanovicTech Alright, thanks for sharing your thoughts.
Ћао, одлична библиотека и видео.
Имам предлог, а то је да направиш додатни видео да покажеш како да се са Refit-ом и на пример са Polly-ем постигне поузданост, на пример ако неки захтев пукне, па да га пошаље поново.
is it really that much trouble to write in English?
Polly има готову библиотеку коју можемо да углавимо овде, можда је више тема за блог него за видео.
@Rob_III What's wrong with some Serbian? 😁 He was suggesting to make a video about Polly and adding resiliency to HTTP client requests.
@@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.
@@Rob_III If you don't speak english or understand it. You might not trust translators. Which I can completely understand.
Nice video! I'm from Brazil
Thanks from Serbia :)
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 ?
Most of the tech giants use int, it has significantly better performance than uuid.
Just don't use it as clustered index in db
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
I would suggest ULID by Cysharp
@@MilanJovanovicTech It would be nice to have a video discussing the following topics: UUID, GUID, ULID, Snowflake ID (probably more).
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.
HttpResponseMessage and parse the response...
@@MilanJovanovicTech or just catch an exception which also contains the content and can be deserialized as required type.
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.
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.
Maybe for personal projects. But I couldn't see myself using this for production work projects.
Why?
@@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.
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.
@MilanJovanovicTech, a bit off topic, but are there any reasonably decent alternatives to Swagger’s UI?
Not that I know, but I haven't really looked for any
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
Shouldn't it just work? Not sure which part is missing with Autofac?
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.
A delegating handler that caches based on the URL params could get the job done
@@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 🤘.
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 ...
1) Don't care, I still like using it as a convention. Nothing wrong with that.
2) Fair point. 👍
Really nice library. Not yet try it. But, can it also handle http status also?
Found it!! In the documentation. We can use `ApiResponse` 😇
You can get back an HttpResponseMessage
How much slower is the compilation because of source generation?
At least 2 eternities on my microwave...
Similar to FeignClient in Java/Springboot
That's cool, I like learning about Java libraries that do the same thing
@@MilanJovanovicTech yes that's why Refit is familiar :D Thanks for this interesting library :D
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
Wrap it into an Either before returning?
@@MilanJovanovicTech Exactly what I did but Refit is throwing deserialisation error
@@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 ?