Other Ways of Making HTTP Requests
Refit and RestSharp are just two of many libraries solving the problem of code duplication when using HttpClient
. Flurl and TinyRest are another two popular alternatives. New libraries are created every year and they are ever evolving. There is no one best way that suits all scenarios. To be sure you make the right choice, you'll want to do a little research first as there are some pitfalls to these alternatives to consider.
HttpClient
was designed for the lowest-level HTTP calls in .NET. It is the safest option because it is well-documented, tested, and allows the most freedom. Though there are many libraries that are much simpler to use than HttpClient
, they often target basic scenarios (no authorization, no dynamically set headers). When it comes to creating advanced HTTP calls, they often turn out to be quite complicated.
When it comes to choosing which client to use, first go for the one provided natively by the API. If there...