-
-
Save Adolfi/e4eb8ec169655c8b7c71cbcc4b0c4e81 to your computer and use it in GitHub Desktop.
This file contains 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
public class PageApiController : UmbracoApiController | |
{ | |
private readonly ILogger<PageApiController> logger; | |
private readonly HttpClient httpClient; | |
public PageApiController(IHttpClientFactory httpClientFactory, ILogger<PageApiController> logger) | |
{ | |
this.contentService = contentService; | |
this.httpClient = httpClientFactory.CreateClient(); | |
this.logger = logger; | |
} | |
public async Task<HttpResponseMessage> CallExternalApi() | |
{ | |
var request = new HttpRequestMessage(HttpMethod.Get, "https://google.com"); | |
this.logger.LogInformation("Calling {HttpMethod} {RequestUri} at: {Now}", request.Method, request.RequestUri, DateTime.Now); | |
var timer = Stopwatch.StartNew(); | |
var response = await httpClient.SendAsync(request); | |
timer.Stop(); | |
this.logger.LogInformation("Response: StatusCode: {StatusCode}. Executed in: {Elapsed}", response.StatusCode, timer.Elapsed); | |
return response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment