Skip to content

Instantly share code, notes, and snippets.

@TechWatching
Created January 28, 2020 13:07
Show Gist options
  • Save TechWatching/2c07e0a7c08152cff8e1f145aa1671cd to your computer and use it in GitHub Desktop.
Save TechWatching/2c07e0a7c08152cff8e1f145aa1671cd to your computer and use it in GitHub Desktop.
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