Skip to the content.

What’s Custard?

NuGet

Custard is a .NET standard plugin to call web APIs intuitively. 😁

Fully compatible with:

Documentation πŸ“„

Installation

Service yourService = new Service(string host, int port = 80, bool sslCertificate = false); 

Passing Parameters to your requests

Custard now supports two types of parameters:

Path parameters

To pass path parameters to your requests, you have to pass them as string[]:

E.g: for /users/api/2/3/4 we would use:

string action = "users";
string controller = "api";
string[] param = { "2", "3", "4" };
           
var resultStr = await yourService.Get(controller: controller,
                                      action: action,
                                      parameters: param);

Query parameters

To pass query parameters to your requests, you have to pass them as Dictionary<string, string>:

E.g: for /users/api?two=2&three=3&four=4 we would use:

string action = "users";
string controller = "api";

Dictionary<string, string> param = new Dictionary<string, string>
{
    { "two", "2" },
    { "three", "3" },
    { "four", "4" }
};
           
var resultStr = await yourService.Get(controller: controller,
                                      action: action,
                                      parameters: param);

⚠ If you want to return a model, the HTTP response body has to be in JSON format

Cancellation Token

From v0.3.5, you can now add a cancellation token to you request.

using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
var cancelationToken = cancellationTokenSource.Token;
//

// Act
Task task =  _wService.Get(controller: controller,
                                cancellationToken: cancelationToken);