Skip to content

opxw/Opx.HttpClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Oct 4, 2024
1c7c35f · Oct 4, 2024

History

7 Commits
Oct 4, 2024
Oct 3, 2024
Oct 3, 2024
Oct 4, 2024
Oct 3, 2024

Repository files navigation

Opx.HttpClient

HTTP Client tools, simplify HttpClient.

NuGet version (Opx.HttpClient)

Usage

Basic

var api = new ApiRequest("https://localhost");

// https://localhost/customers
var customers = await api.RequestJsonAsync<List<Customer>>(HttpMethod.Post, "customers");

Parameter From Query

// https://localhost/customers?Active=true&Sort=name
var customers = await api.RequestJsonAsync<List<Customer>>(HttpMethod.Get, "customers", new ApiRequestParameter()
{
    FromQuery = new
    {
        Active = true,
        Sort = "name"
    }
);

Parameter From Route

// https://localhost/customers/1
var customer = await api.RequestJsonAsync<Customer>(HttpMethod.Get, "customers/{Id}", new ApiRequestParameter()
{
    FromRoute = new
    {
        Id = 1
    }
);

Parameter From Body

// https://localhost/customers/save
var success = await api.RequestJsonAsync<bool>(HttpMethod.Post, "customers/save", new ApiRequestParameter()
{
    FromBody = new
    {
        Id = 1,
        FirstName = "John",
        LastName = "Doe"
    }
);

You can mix those parameters together.

HTTP Request Version

Default RequestVersion is HTTP/2

var doc = new DocRequest("https://tools.keycdn.com/http2-test", HttpRequestVersion.Http20);
var res = doc.RequestString(HttpMethod.Get);

For HTTP/3 you must set httpVersionPolicy to HttpVersionPolicy.RequestVersionExact

var doc = new DocRequest("https://cloudflare-quic.com", HttpRequestVersion.Http30, HttpVersionPolicy.RequestVersionExact);
var res = doc.RequestString(HttpMethod.Get);

About

HTTP Client tools

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages