Skip to content
Anrijs Vitolins edited this page Feb 21, 2022 · 4 revisions

Since .Net Core 3, Microsoft changed the way how .Net code can access and use HTTP based APIs (Services) exposing data as JSON contracts. You can read more details in official documenatation or check this blog on these features.

Still - plain HttpClient is demanding quite a boilerplate code to write (setting up HttpRequest, serializing, deserializing etc.). Thus - this repository and related NuGet package helps to get extension methods and setup around it for easier usage patterns.

Package is capable of working in all three usage scenarios - simple Factory approach, Named factory approach and Typed client approach. Just use appropriate constructor and configuration for each approach - see separate Wiki pages how to use it in each scenatios.

Package includes ability to construct API URLs via parameters similarly (but not fluently) like Flurl does it to avoid magic strings a bit more.

Package has built-in two JSON serializer implementations - Json.Net (default) or System.Text.Json to seamlessly serialize and deserialize your request and response data objects.

It has ability to add default headers for each request (read from settings), wire up username:password basic authentication, if service is using it or call overridable method to get token/apikey before each call to service to add it to authentication header for it.

Upon any problems with service call (work endpoint, wrong verb, wrong request/response data contract, general problems), package is filling provided RestClientException object with all request and response data and throws it four your aplication to catch and use in error reporting.

There is also built-in timer to get entire call execution time, which you can read right after call and append it to some monitoring service.

Package takes ILogger instance and does extensive (Verbose) logging on all internal steps performed by it, Debug level logs for few general happenings, which can be used during application development to quickly understand what and where goes wrong.

NOTE: Package embraces NULLABLE reference types.

Clone this wiki locally