Created
April 22, 2022 14:30
-
-
Save alexandrebl/6a7d8879b5798f073514444cbf891ac7 to your computer and use it in GitHub Desktop.
Dependency Injection Named Http Client Factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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