Skip to content

Instantly share code, notes, and snippets.

@chinhvo
Forked from shubhamnikam/Startup.cs
Created August 21, 2023 02:43
Show Gist options
  • Save chinhvo/92d219a34ee8bde8b163a4d7855cee2a to your computer and use it in GitHub Desktop.
Save chinhvo/92d219a34ee8bde8b163a4d7855cee2a to your computer and use it in GitHub Desktop.
Setup HttpClient configuration in Startup.ConfigureService
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
//configure httpclient service
services.AddHttpClient("GithubAPI", client=>
{
//customize as per your need
client.BaseAddress = new Uri("http://api.github.com/");
client.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json");
client.DefaultRequestHeaders.Add("User-Agent", "HttpClientFactoryExample");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment