ObjectUrl.Core 0.1.0-preview3

This is a prerelease version of ObjectUrl.Core.
There is a newer prerelease version of this package available.
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                
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="ObjectUrl.Core" Version="0.1.0-preview3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ObjectUrl.Core --version 0.1.0-preview3                
#r "nuget: ObjectUrl.Core, 0.1.0-preview3"                
#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 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

build release

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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 87 2/9/2024
0.1.0-preview6 66 1/31/2024
0.1.0-preview5 62 1/30/2024
0.1.0-preview4 62 1/30/2024
0.1.0-preview3 67 10/11/2023
0.1.0-preview2 94 10/8/2023
0.1.0-preview1 78 10/7/2023