Skip to content

Latest commit

 

History

History
45 lines (36 loc) · 2.12 KB

README.md

File metadata and controls

45 lines (36 loc) · 2.12 KB

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:

    _networkMonitor = new WindowsNetworkMonitor();
    _nativeHttpClient = new WindowsHttpClient(_networkMonitor);
    _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.