ObjectUrl.Core
0.1.0-preview3
See the version list below for details.
dotnet add package ObjectUrl.Core --version 0.1.0-preview3
NuGet\Install-Package ObjectUrl.Core -Version 0.1.0-preview3
<PackageReference Include="ObjectUrl.Core" Version="0.1.0-preview3" />
paket add ObjectUrl.Core --version 0.1.0-preview3
#r "nuget: ObjectUrl.Core, 0.1.0-preview3"
// Install ObjectUrl.Core as a Cake Addin #addin nuget:?package=ObjectUrl.Core&version=0.1.0-preview3&prerelease // Install ObjectUrl.Core as a Cake Tool #tool nuget:?package=ObjectUrl.Core&version=0.1.0-preview3&prerelease
<img src="images/icon.png" width="100" height="100" alt="icon">
ObjectUrl: Documented API objects
This package came into existence after having to use countless external APIs and dealing with documenting their query parameters, path variables, and response types.
Encapsulate API call requirements within a single object that can be used with the HttpClient
without relying on building typed http clients that you inject as constructor arguments.
The idea is simple: create a class that models a request and send the request. That's it.
[Endpoint("api/query/{id}")] // The API endpoint
public class MyApiRequest : Input<MyApiResponse> // MyApiResponse is the expected JSON format
{
[PathParameter("id")] // Property value replaces the path variable {id}
public Guid Id { get; set; }
[QueryParameter("amount")]
public required decimal Amount { get; set; }
[QueryParameter("credit-debit")]
public required string CreditDebit { get; set; }
}
No need to register anything with the dependency injection container. Just use it with the native HttpClient
you already
know and love.
var input = new MyApiRequest
{
Id = Guid.Parse("d65ce0f6-2cec-4a94-8a84-bee4dca75a01"),
Amount = 100,
CreditDebit = "Credit"
};
using var client = new HttpClient
{
BaseAddress = new Uri("http://localhost:5043")
};
MyApiResponse? result = await client.SendRequestAsync(input);
// -> http://localhost:5043/api/query/d65ce0f6-2cec-4a94-8a84-bee4dca75a01?amount=100&credit-debit=Credit
Query strings that are list values
You can easily create a multi-value query string, or define your own delimiter for list values.
// Multi-value query string
[QueryParameter("values")]
public IEnumerable<string> Values { get; set; } = new []{"one", "two"}
// -> ?values=one&values=two
// Custom value delimiter
[QueryParameter("values")]
[QueryList(delimiter: ",")]
public IEnumerable<string> Values { get; set; } = new []{"one", "two"}
// Notice the comma is url encoded
// -> ?values=one%2ctwo
Generate code coverage report
Run the generate-report.sh
script.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. |
-
net7.0
- No dependencies.
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.1.0-preview7 | 79 | 2/9/2024 |
0.1.0-preview6 | 62 | 1/31/2024 |
0.1.0-preview5 | 58 | 1/30/2024 |
0.1.0-preview4 | 57 | 1/30/2024 |
0.1.0-preview3 | 63 | 10/11/2023 |
0.1.0-preview2 | 88 | 10/8/2023 |
0.1.0-preview1 | 74 | 10/7/2023 |