Skip to content

All the best practices of using HttpClient in just one library.

License

Notifications You must be signed in to change notification settings

evgenyvalavin/Arbus.Network

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arbus.Network

Build Status

Working with an HttpClient in C# could be quite tricky as for new and as for experienced software developers. Network code usually appears to be duplicated in multiple projects. Such code is hard to maintain and improve.
At Arbus, we are excited to share the network code we've been working on for more than two years. We wanted to write network code that'll be possible to reuse in wide range of solutions. There're two principles of software development we mostly kept in our minds: DRY and Single-responsibility principles. We believe an Open Source community will attract passionate developers like us. Everyone is welcome to contribute.

Let's build a better world together!

Features

  • ApiEndpoints is the perfect place for request/response pair details.
  • HttpTimeout handling.
  • Built-in JSON support.
  • ProblemDetails format support for non-success responses.
  • Built-in NetworkExceptions.
  • Highly customizable for different needs

How to use

  1. Provide your own implementation or use default one for interfaces: INetworkManager, INativeHttpClient, IHttpClientContext:

    _networkManager = new WindowsNetworkManager();
    _nativeHttpClient = new WindowsHttpClient(_networkManager);
    _httpClientContext = new HttpClientContext(_nativeHttpClient);
  2. Use ApiEndpoint as base class for your API endpoints:

    public class GetAllOrdersApiEndpoint : ApiEndpoint<OrdersResponseDto>
    {
        public GetAllOrdersApiEndpoint()
            : base(HttpMethod.Get, "https://example.com/api/v1/orders")
        {
        }
    }
  3. Run your endpoint:

    GetAllOrdersApiEndpoint endpoint = new();
    var orders = await _httpClientContext.RunEndpoint(endpoint).ConfigureAwait(false);

Take a look at samples in the repo's root.

Downloads

The latest stable release of Arbus.Network is available on NuGet.

About

All the best practices of using HttpClient in just one library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%