Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 1.15 KB

README.md

File metadata and controls

39 lines (27 loc) · 1.15 KB

Slow.Utilities.Http

Simple HTTP utilities to make using HttpClient easier.

Usage

Examples of using HttpRequestBuilder:

using static Slow.Utilities.Http.HttpRequestBuilder;

var getRequest = Get($"api/v1/things")
    .WithQueryParameter("page", 3);
var getResponse = await httpClient.SendAsync(getRequest);

var getRequest2 = Get($"api/v1/thing/{thingId}")
    .WithQueryParameter("page", 3);
var getResponse2 = await httpClient.SendAsync(getRequest2);

var postRequest = Post($"api/v1/things")
    .WithJsonContent(new { ThingId = 1, ThingName = "foo" });
var postResponse = await httpClient.SendAsync(getRequest);

How to use RetryHandler with HttpClientFactory

services.AddTransient<Slow.Utilities.Http.RetryHandler>();
services.AddHttpClient("SomeApi", (client) =>
{
    client.BaseAddress = new Uri(configuration["SomeApi:BaseAddress"]);
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Json));
}).AddHttpMessageHandler<Slow.Utilities.Http.RetryHandler>();

Built with ♥ by Calvin.