Skip to content

Latest commit

 

History

History
57 lines (45 loc) · 1.43 KB

README.md

File metadata and controls

57 lines (45 loc) · 1.43 KB

HttpBuilder

Http helper to build and observe http requests.

Get started

0. Installation from Nuget console.

Install-Package HttpBuilder -Version 1.0.0

1. Create your service.

using HttpBuilder;

// Service to create requests and observe them
class MyHttpService : HttpService
{
        protected override void ConfigureHandler(HttpClientHandler handler)
        {
          /// Configure your handler
        }

        protected override void ConfigureClient(HttpClient client)
        {
          /// Configure your client
        }
        
        // Many additional overrides
}

2. Use the service as start point.

var service = new MyHttpService();

// Sample
var result = await service.Build($"api/v3/insurances") // Creates a relative request
  .WithParameter("parameter", parameter) // Custom query parameter
  .Get()
  .Send(token) // Sends the built request
  .ValidateSuccessStatusCode()
  .Json<InsuranceDTO[]>(JsonHelper.Serializer) // Parse json
  .Continue(x => x.FirstOrDefault(y => y.Id == id)) // Additional conversion. May be async
  .Task;
                
// Supports uploading
await service.Build($"api/v3/insurances")
  .Get()
  .Send(HttpCompletionOption.ResponseHeadersRead)
   // Process the loading progress for big files
  .ProcessLoading(token, destinationStream, 4096, (totalBytes, readedBytes, percentage) => { /* reporting */ })
  .ValidateSuccessStatusCode()
  .Task;