Custard 0.3.7
See the version list below for details.
dotnet add package Custard --version 0.3.7
NuGet\Install-Package Custard -Version 0.3.7
<PackageReference Include="Custard" Version="0.3.7" />
<PackageVersion Include="Custard" Version="0.3.7" />
<PackageReference Include="Custard" />
paket add Custard --version 0.3.7
#r "nuget: Custard, 0.3.7"
#:package Custard@0.3.7
#addin nuget:?package=Custard&version=0.3.7
#tool nuget:?package=Custard&version=0.3.7
<p align="center" class="container" > <img width="200px" src="https://user-images.githubusercontent.com/37577669/85275198-47b3ca00-b480-11ea-8273-d990295416a7.png" />
</p>
What's Custard?
Custard is a .NET standard plugin to call web APIs intuitively. 😁
Fully compatible with:
- .NET MAUI
- Xamarin Forms
Documentation 📄
Installation
- Package manager
Install-Package Custard -Version 0.3.7 - .NET CLI
dotnet add package Custard --version 0.3.7
Custard.Service
Instantiate a service object:
Service yourService = new Service(string host, int port = 80, bool sslCertificate = false);
Create headers
yourService.RequestHeaders.Add("Hearder", "Value "); // Do this for every headers
⚠ For every method below, we recommend being very explicit with your parameters. As there are too many options for parameters, this could lead to ambiguities.
e.g: use
Get(controller: theController)instead ofGet(theController)
Call a POST method
Parameters:
Name Type Required controller string✔ action string❌ headers IDictionary<string, string>❌ jsonBody string❌ parameters string[] / IDictonary<string,string>❌ Usage:
- To return a string:
yourService.Post (controller: controller, action: action, singleUseHeaders: headers, jsonBody: jsonBody, parameters: parameters); - To return a model (T is the model):
yourService.Post<T> (controller: controller, action: action, singleUseHeaders: headers, jsonBody: jsonBody, parameters: parameters);
- To return a string:
Call a PUT method
Parameters:
Name Type Required controller string✔ action string❌ headers IDictionary<string, string>❌ jsonBody string❌ parameters string[] / IDictonary<string,string>❌ Usage:
- To return a string:
yourService.Put (controller: controller, action: action, singleUseHeaders: headers, jsonBody: jsonBody, parameters: parameters); - To return a model (T is the model):
yourService.Put<T> (controller: controller, action: action, singleUseHeaders: headers, jsonBody: jsonBody, parameters: parameters);
- To return a string:
Call a GET method
Parameters:
Name Type Required controller string✔ action string❌ headers IDictionary<string, string>❌ jsonBody string❌ parameters string[] / IDictonary<string,string>❌ Usage:
- To return a string:
yourService.Get (controller: controller, action: action, singleUseHeaders: headers, jsonBody: jsonBody, parameters: parameters);- To return a model (T is the model):
yourService.Get<T> (controller: controller, action: action, singleUseHeaders: headers, jsonBody: jsonBody, parameters: parameters);
Passing Parameters to your requests
Custard now supports two types of parameters:
- Path parameters
- Query 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);
Callback Error
If needed, you can add a callback if the request faces an HTTP error. This will work with any method mentioned above. This will allow you to do an handle the error more easily. Here's how it works:var actualResult = await yourService.Get(controller: "todolists", singleUseHeader: headers, callbackError: (err) => { });- code: the error status code (HttpStatusCode).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.NET.Test.Sdk (>= 17.9.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.4.0.4-rc | 465 | 10/26/2025 |
| 0.4.0.3-rc | 179 | 10/26/2025 |
| 0.4.0.2-rc | 184 | 10/26/2025 |
| 0.4.0.1-rc | 183 | 10/26/2025 |
| 0.3.9-rc | 127 | 10/24/2025 |
| 0.3.8.1-rc | 144 | 12/2/2024 |
| 0.3.8-rc | 133 | 12/2/2024 |
| 0.3.7 | 2,297 | 4/29/2024 |
| 0.3.6.1-rc | 302 | 4/8/2024 |
| 0.3.6-rc | 224 | 3/13/2024 |
| 0.3.5.1-rc | 331 | 2/28/2024 |
| 0.3.5 | 304 | 3/11/2024 |
| 0.3.5-rc | 253 | 2/24/2024 |
| 0.3.4-rc | 253 | 2/21/2024 |
| 0.3.3 | 393 | 2/17/2024 |
| 0.3.3-rc | 375 | 2/13/2024 |
| 0.3.2.1-rc | 866 | 8/24/2023 |
| 0.3.2 | 346 | 2/10/2024 |
| 0.3.2-rc | 663 | 12/8/2022 |