HttpApiClient 1.0.6
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package HttpApiClient --version 1.0.6
NuGet\Install-Package HttpApiClient -Version 1.0.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HttpApiClient" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HttpApiClient --version 1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: HttpApiClient, 1.0.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install HttpApiClient as a Cake Addin #addin nuget:?package=HttpApiClient&version=1.0.6 // Install HttpApiClient as a Cake Tool #tool nuget:?package=HttpApiClient&version=1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
HttpApiClient
Simple client library for parsing HTTP API responses.
In order to use it, add the following nuget packages to your project (order is important):
- Microsoft.Bcl.Build 1.0.21
- Microsoft.Net.Http 2.2.29
- HttpApiClient 1.0.5
- Newtonsoft.Json 11.0.1 (optional, needed if using JsonParser)
Samples
Check HttpApiClient.Tests project for running code.
GET requests
private async Task<Product> ReadAsync(int productId)
{
var config = new Config($"localhost:64195/api/products/{productId}", false);
var request = new GetRequest(config, _responseLogger);
var response = await request.RunAsync<JsonParser>();
Product product = null;
(await request.RunAsync<JsonParser>())
.OnSuccess(parser => product = parser.To<Product>())
.OnAnyFailureThrow();
return product;
}
private async Task<IList<Product>> ReadAllAsync()
{
var request = new GetRequest(new Config($"localhost:64195/api/products", false), _responseLogger);
IList<Product> products = null;
(await request.RunAsync<JsonParser>())
.OnSuccess(parser => products = parser.To<IList<Product>>())
.OnAnyFailureThrow();
return products;
}
POST request
private async Task<Product> CreateAsync(Product newProduct)
{
var config = new UploadConfig(
$"localhost:64195/api/products",
false,
JsonConvert.SerializeObject(newProduct));
var request = new PostRequest(config, _responseLogger);
Product product = null;
var response = await request.RunAsync<JsonParser>();
if (response.IsSuccessfull())
{
product = response.TypedParser.To<Product>();
}
return product;
}
PUT request
private async Task UpdateAsync(Product product)
{
var config = new UploadConfig(
$"localhost:64195/api/products/{product.Id}",
false,
JsonConvert.SerializeObject(product));
var request = new PutRequest(config, _responseLogger);
var response = await request.RunAsync<JsonParser>();
response.OnAnyFailureThrow();
}
DELETE request
private async Task DeleteAsync(int productId)
{
var config = new Config($"localhost:64195/api/products/{productId}", false);
var deleteRequest = new DeleteRequest(config, _responseLogger);
var response = await deleteRequest.RunAsync<JsonParser>();
response.OnAnyFailureThrow();
}
There are no supported framework assets in this package.
Learn more about Target Frameworks and .NET Standard.
-
- Microsoft.Bcl (>= 1.1.10)
- Microsoft.Bcl.Build (>= 1.0.21)
- Microsoft.Net.Http (>= 2.2.29)
- Newtonsoft.Json (>= 11.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on HttpApiClient:
Package | Downloads |
---|---|
Orb.DearSystems
Orb implmentation of the DearSystems API client |
GitHub repositories
This package is not used by any popular GitHub repositories.
Added ConsoleResponseLogger and JsonParserExtensions.