A simple wrapper around Flurl.Http that allows you to easily make http requests and deserialize the response.
$ dotnet add package FlurlHttpClientA simple wrapper around Flurl.Http that allows you to easily make http requests and deserialize the response.
Add FlurlHttpClient to your services in your Startup.cs or Program.cs file .
services.AddFlurlHttpClient();
Inject IHttpClientService into your class and use it to make http requests.
public class MyService:IMyService
{
private readonly IHttpClientService _flurlHttpClient;
public MyService(IHttpClientService flurlHttpClient)
{
_flurlHttpClient = flurlHttpClient;
}
public async Task<MyResponse> GetMyResponse()
{
var request=HttpClientRequest<object>{
Url="https://api.example.com/my-endpoint",
Token="token",
IsOauthToken=false,
Data=null
};
return await _flurlHttpClient.GetAsync<MyResponse,object>(request);
}
}
// your response model
public class MyResponse
{
// your properties
}
GetAsync<TP,T>(HttpClientRequest request) : Make a get requestPostAsync<TP,T>(HttpClientRequest< request) : Make a post requestPutAsync<TP,T>(HttpClientRequest<T> request) : Make a put requestDeleteAsync<TP,T>(HttpClientRequest<T> request) : Make a delete requestPatchAsync<TP,T>(HttpClientRequest<T> request) : Make a patch requestPostFormDataAsync<PT,T>(HttpClientRequest<T> request) : Make a multipart form data requestThe HttpClientRequest class is used to pass the request. It contains the following properties:
Url : The url of the requestToken : The authorization token to be used for the requestIsOauthToken : A boolean indicating if the token is an oauth token or jwt tokenData : The data to be sent with the request bodyThe ApiResults<T> class is used to return the response from the http request. It contains the following properties:
Data : The response dataCode : The status code of the responseMessage : The message of the responseIsSuccessful : A boolean indicating if the request was successfulThis project is licensed under the MIT License.
This project is licensed under the MIT License.
For any questions or issues, please open an issue on GitHub or contact us at developer.biliksuun@gmail.com.