HttpClient.Abstractions
HttpClientAbstractions Stable
Nuget 패키지 : https://www.nuget.org/packages/httpclient.abstractions/
httpclient.abstractions는 system.net.http.httpclient에 대한 완전히 추상화를 제공하는 경량 패키지입니다. 패키지는 다음으로 구성됩니다.
public class HttpClientConsumer
{
public string BaseUrl { get ; set ; }
private IHttpClient _client ;
[ importing constructor ]
public HttpClientConsumer ( IHttpClient client ) {
_client = client ;
_client . BaseAddress = BaseUrl ;
}
//Get
public async IEnumerable < CustomrerDto > GetCustomersAsync ( ) {
IHttpResult result = await _client . GetAsync < IEnumerable < CustomerDto > > ( "customers" ) ;
return result . Content ;
}
//Post
public async void CreateCustomerAsync ( CustomerDto customer ) {
IHttpResult result = await _client . PostAsync < CustomerDto > ( "customers" , customer ) ;
//handle result...
}
//Put
public async void ReplaceCustomerAsync ( CustomerUpdateDto customer ) {
IHttpResult result = await _client . PutAsync < CustomerUpdateDto > ( $ "customers/ { customer . id } " , customer ) ;
}
//Patch
public async void UpdateCustomerAsync ( CustomerPatchDoc patchDoc ) {
IHttpResult result = await _client . PatchAsync < CustomerPatchDoc > ( $ "customers/ { patchDoc . id } " , patchDoc ) ;
}
//Delete
public async void RemoveCustomerAsync ( CustomerDto customer ) {
IHttpResult result = await _client . DeleteAsync ( $ "customers/ { customer . id } " ) ;
}
}