HttpApiClient 1.0.6

There is a newer version of this package available.
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                
#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                

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):

  1. Microsoft.Bcl.Build 1.0.21
  2. Microsoft.Net.Http 2.2.29
  3. HttpApiClient 1.0.5
  4. 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.

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.

Version Downloads Last updated
1.0.7 2,265 3/20/2018
1.0.6 964 2/20/2018
1.0.5 829 2/20/2018
1.0.4 924 5/23/2017
1.0.3 940 11/16/2016
1.0.2 1,071 11/3/2016
1.0.1 1,049 11/3/2016
1.0.0 953 9/8/2016

Added ConsoleResponseLogger and JsonParserExtensions.