Created
January 28, 2020 13:07
-
-
Save TechWatching/2c07e0a7c08152cff8e1f145aa1671cd to your computer and use it in GitHub Desktop.
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
public class UserService : | |
{ | |
private readonly HttpClient _httpClient; | |
public UserService(HttpClient httpClient) | |
{ | |
_httpClient = httpClient; | |
} | |
public async Task<IReadOnlyCollection<User>> GetAllUsers() | |
{ | |
var response = await _httpClient.GetAsync(new Uri("user")); | |
response.EnsureSuccessStatusCode(); | |
return await response.Content.ReadAsAsync<IReadOnlyCollection<User>>(); | |
} | |
public async Task UpdateUser(User userToUpdate) | |
{ | |
var content = new StringContent(JsonConvert.SerializeObject(userToUpdate)); | |
var response = await _httpClient.PutAsync($"user/{userToUpdate.Name}", content); | |
response.EnsureSuccessStatusCode(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment