Skip to content

lukasrochaaraujo/HTTPRequest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTPRequest

NuGet package build

Simple library to make HTTP requests using JSON

Dependecies

  • .NET Standard 2.x
  • Microsoft.Extensions.DependencyInjection.Abstractions 6.x
  • Newtonsoft.Json 13.x

Example with bearer auth

var httpRequest = new HttpRequest();
httpRequest.AppendHeader("Authorization", "Bearer token")
await httpRequest.GETAsync<IEnumerable<Employer>>("https://api.server.com/employer");

HttpRequest options

new HttpRequest(new HttpRequestOptions()
{
    DateTimeFormat = "iso_datetime_format",
    TimeOutInSeconds = 30,
    MaxRequestAttempts = 3,
    IntevalBetweenAttemptsInSeconds = 5
});

HttpRequest Dependency Injection

(...)
services.AddHttpRequest(); //simple with default options values
//OR
services.AddHttpRequest(provider => //with custom options values
{
    return new HttpRequest(new HttpRequestOptions
    {
        TimeOutInSeconds = 120,
        MaxRequestAttempts = 5
        (...)
    });
});
(...)
//Constructor DI
(...)
private readonly IHttpRequest _httpRequest;

public MyClass(IHttpRequest httpRequest)
{
    _httpRequest = httpRequest;
}
(...)

Methods

void AppendHeader(string key, string value);

void RemoveHeader(string key);

void ClearHeaders();

async Task<T> GETAsync<T>(string url);

async Task<T> POSTAsync<T>(string url, string jsonData);

async Task<T> PUTAsync<T>(string url);

async Task<T> PUTAsync<T>(string url, string jsonData);

async Task DELETEAsync<T>(string url);