RequesterNetLib 1.0.0
See the version list below for details.
dotnet add package RequesterNetLib --version 1.0.0
NuGet\Install-Package RequesterNetLib -Version 1.0.0
<PackageReference Include="RequesterNetLib" Version="1.0.0" />
paket add RequesterNetLib --version 1.0.0
#r "nuget: RequesterNetLib, 1.0.0"
// Install RequesterNetLib as a Cake Addin
#addin nuget:?package=RequesterNetLib&version=1.0.0
// Install RequesterNetLib as a Cake Tool
#tool nuget:?package=RequesterNetLib&version=1.0.0
RequesterNet
RequesterNet is a simple and fast REST and HTTP API Client for .NET Core.
Getting started
First, install the package by executing the following command:
PM> Install-Package RequesterNetLib
Then, in your ConfigureServices method use:
public void ConfigureServices(IServiceCollection services)
{
services.AddRequesterNet();
}
Or with options:
public void ConfigureServices(IServiceCollection services)
{
services.AddRequesterNet(opt =>
{
opt.UrlBase = "https://example.com",
opt.DefaultHeaders = new Dictionary<string, string>
{
{ "Authorization", "Bearer myBearerToken" }
}
});
}
Option | Description | Type | Default |
---|---|---|---|
UrlBase | Set the base url for all calls when using RequesterNet. | string | null |
DefaultHeaders | Set the default headers for all calls when using RequesterNet. | Dictionary<string, string> | empty |
Usage
Use the interface IRequesterNet in constructor:
private readonly IRequesterNet _requester;
public MyClass(IRequesterNet requester)
{
_requester = requester;
}
Get
A simple Get request (if a base url is setted only "/endpoint" is required):
public void Get()
{
var response = await _requester.GetAsync("https://example.com/endpoint");
}
Get (parameters and headers)
RequesterNet helps with binding parameters and headers in any request. A simple Get request with custom parameters and headers:
public void Get()
{
var parameters = new Dictionary<string, string>
{
{ "search", "foo" },
{ "page", "1" }
};
var headers = new Dictionary<string, string>
{
{ "Authorization", "Bearer myBearerToken" },
{ "x-api-key", "myApiKey" }
};
var response = await _requester.GetAsync("https://example.com/endpoint", parameters, headers);
//Final url results in: https://example.com/endpoint?search=foo&page=1
}
Post
Post method follows the same parameters like Get but with a optional body object, example:
public void Post()
{
var parameters = new Dictionary<string, string>
{
{ "search", "foo" },
{ "page", "1" }
};
var headers = new Dictionary<string, string>
{
{ "Authorization", "Bearer myBearerToken" },
{ "x-api-key", "myApiKey" }
};
var body = new
{
Username = "myUsername",
Password = "myPassword"
};
var response = await _requester.PostAsync("https://example.com/endpoint", parameters, headers, body);
}
Other methods
RequesterNet has the common http methods, being:
Method | Url | Parameters | Headers | Body |
---|---|---|---|---|
GetAsync | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
PostAsync | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
PutAsync | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
PatchAsync | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
DeleteAsync | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Options (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.