Skip to content

Instantly share code, notes, and snippets.

@alexandrebl
Created April 22, 2022 14:30
Show Gist options
  • Select an option

  • Save alexandrebl/6a7d8879b5798f073514444cbf891ac7 to your computer and use it in GitHub Desktop.

Select an option

Save alexandrebl/6a7d8879b5798f073514444cbf891ac7 to your computer and use it in GitHub Desktop.
Dependency Injection Named Http Client Factory
builder.Services.AddHttpClient("GitHub", httpClient =>
{
httpClient.BaseAddress = new Uri("https://api.github.com/");
// using Microsoft.Net.Http.Headers;
// The GitHub API requires two headers.
httpClient.DefaultRequestHeaders.Add(
HeaderNames.Accept, "application/vnd.github.v3+json");
httpClient.DefaultRequestHeaders.Add(
HeaderNames.UserAgent, "HttpRequestsSample");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment