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

preview_player
Показать описание

The easy way to make HTTP requests in .NET is to use the HttpClient to send those requests. And it's a great abstraction to work with, especially with the methods supporting JSON payloads and responses. Unfortunately, it's easy to misuse the HttpClient. Port exhaustion and DNS behavior are some of the most common problems. Enter Refit: the automatic type-safe REST library for .NET Core. In this video, I'll show you how to use Refit to easily integrate with an HTTP API.

The Right Way To Use HttpClient In .NET

Join my weekly .NET newsletter:

Read my Blog here:

Chapters
0:00 GitHub API integration with HttpClient
4:54 Replacing HttpClient with Refit
10:03 Creating a PATCH endpoint with Refit
Рекомендации по теме
Комментарии
Автор

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

ahmedrizk
Автор

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

GeorgiosNtomoras
Автор

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

xavier.xiques
Автор

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

Rob_III
Автор

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 ?

enricoroselino
Автор

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.

jimgilmartin
Автор

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

MikkalYT
Автор

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

davearkley
Автор

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

baranacikgoz
Автор

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

VoroninPavel
Автор

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.

JuanOG
Автор

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)

joga_bonito_aro
Автор

How much slower is the compilation because of source generation?

cuachristine
Автор

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.

rengstrom
Автор

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

adamchubbuck
Автор

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

amierulbasyaryusoff
Автор

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

vgwizardx
Автор

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

milutinke
Автор

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

Автор

Similar to FeignClient in Java/Springboot

benjsoft