This library simplifies API client creation
BaseClient class methods
- GetAsync - retrieves (reads) data via HTTP GET method
- PostAsync - adds (writes) data via HTTP POST method
- PutAsync - fully updates data via HTTP PUT method
- PatchAsync - partially updates data via HTTP PATCH method
- DeleteAsync - deletes data via HTTP DELETE method
dotnet add package Byndyusoft.ApiClient
To create an API client:
- Create your API client class and derive it from BaseClient class:
public class SomeApiClient : BaseClient
{
public SomeApiClient(HttpClient client, IOptions<ApiClientSettings> apiSettings) : base(client, apiSettings)
{
}
}
- Great! Now you can use the BaseClient methods to declare your methods:
public Task<Model> Create(CreateModelRequest createModelRequest)
=> PostAsync<Model>("api/create", createModelRequest);
public Task Delete(int id)
=> DeleteAsync("api/delete/{id}");
public Task<Model> Get(GetModelRequest getModelRequest) =>
=> GetAsync<GetModelRequest, Model>("api/get, getModelRequest);
- Make sure to register your client wherever you need it:
serviceCollection.AddHttpClient<SomeApiClient>();