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 void ConfigureServices(IServiceCollectionservices) | |
{ | |
services.AddMemoryCache(); | |
services.AddHttpClient<IUserApiAuthenticationService, UserApiAuthenticationService>() | |
.ConfigureHttpClient(c => c.BaseAddress ="http://urltotheuserapi.com"); | |
services.AddTransient<UserApiAuthenticationHandler>(); | |
services.AddHttpClient<UserService, UserService>() | |
.ConfigureHttpClient(c => c.BaseAddress ="http://urltotheuserapi.com") | |
.AddHttpMessageHandler<UserApiAuthenticationHanler>(); |
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 AuthResponse | |
{ | |
public string Token { get; set; } | |
public DateTime Expiration { get; set; } | |
} |
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 interface IUserService | |
{ | |
Task<IReadOnlyCollection<User>> GetAllUsers(); | |
Task UpdateUser(User userToUpdate); | |
} |
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
var body = new { login = "login", password = "password" }; | |
var response = await _httpClient.PostAsync("login", new StringContent(JsonConvert.SerializeObject(body))); | |
var authResponse = await response.Content.ReadAsAsync<AuthResponse>(); |
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 UserService : | |
{ | |
private readonly HttpClient _httpClient; | |
public UserService(HttpClient httpClient) | |
{ | |
_httpClient = httpClient; | |
} | |
public async Task<IReadOnlyCollection<User>> GetAllUsers() | |
{ |
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 UserApiAuthenticationHandler : DelegatingHandler | |
{ | |
private readonly IUserApiAuthenticationService _authenticationService; | |
public UserApiAuthenticationHandler(IUserApiAuthenticationService authenticationService) | |
{ | |
_authenticationService = authenticationService; | |
} | |
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationTokencancellationToken) |
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 UserApiAuthenticationService : IUserApiAuthenticationService | |
{ | |
private readonly IMemoryCache _memoryCache; | |
private readonly HttpClient _httpClient; | |
public UserApiAuthenticationService(HttpClient httpClient, IMemoryCache memoryCache) | |
{ | |
_httpClient = httpClient; | |
_memoryCache = memoryCache; | |
} |
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 UserService : IUserService | |
{ | |
private readonly HttpClient _httpClient; | |
public UserService(HttpClient httpClient) | |
{ | |
_httpClient = httpClient; | |
} | |
public async Task<IReadOnlyCollection<User>> GetAllUsers() | |
{ |
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
#r "nuget: Handlebars.Net, 1.9.5" | |
using HandlebarsDotNet; | |
string html = @" | |
<ul class=""people""> | |
{{#each people}} | |
<li>{{FirstName}} {{LastName}} - {{Job}}</li> | |
{{/each}} | |
</ul>"; |
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
#### List of start wars planets | |
GET https://swapi.co/api/planets/ HTTP/1.1 | |
### Get Luke Skywalker | |
# @name lukeRequest | |
GET https://swapi.co/api/people/?search=Luke HTTP/1.1 | |
### Get Luke Skywalker home planet | |
GET {{lukeRequest.response.body.results[0].homeworld}} HTTP/1.1 |
NewerOlder