Klinkby.Halal
1.0.0
dotnet add package Klinkby.Halal --version 1.0.0
NuGet\Install-Package Klinkby.Halal -Version 1.0.0
<PackageReference Include="Klinkby.Halal" Version="1.0.0" />
paket add Klinkby.Halal --version 1.0.0
#r "nuget: Klinkby.Halal, 1.0.0"
// Install Klinkby.Halal as a Cake Addin #addin nuget:?package=Klinkby.Halal&version=1.0.0 // Install Klinkby.Halal as a Cake Tool #tool nuget:?package=Klinkby.Halal&version=1.0.0
Klinkby.Halal
The Klinkby.Halal
project provides a set of immutable classes that serve as base for creating and managing resources
and links in HAL (Hypertext Application Language) documents. It is designed to facilitate the implementation of
hypermedia-driven RESTful APIs in .NET.
Features
- HAL Resource Representation: Define and manage resources using the
HalResource
andHalResource<TEmbedded>
records. - Link Management: Easily add and manage links to related resources using extension methods.
- Constants for Link Relations: Use predefined constants for common link relation types.
- JSON Serialization: AoT-friendly
System.Text.Json
serialization.
Prerequisites
Installation
To install Klinkby.Halal
, add the following package reference to your project file:
<PackageReference Include="Klinkby.Halal" Version="1.0.0-alpha" />
Usage
The solution provide a sample using the Klinkby.Halal in a AoT Web API project.
A complete resource could be defined as following sample:
public record Dogs : HalResource<DogsEmbed>
{
public Dogs(IEnumerable<Dog> dogs) : base(
HalLinks.Self(
"/dog",
new KeyValuePair<string, HalLink>(
LinkName.Find,
new HalLink("/dog/{id}", templated: true))),
new DogsEmbed(dogs))
{
}
}
public record DogsEmbed(IEnumerable<Dog> Dogs);
public record Dog : HalResource<DogEmbed>
{
public Dog(
int id,
string name,
int breedId,
Breed? breed = null
) : base(
HalLinks.Self(
$"/dog/{id}",
new KeyValuePair<string, HalLink>("breed", $"/breed/{breedId}")),
breed?.ToDogEmbedded())
{
Id = id;
Name = name;
BreedId = breedId;
}
public int Id { get; }
public string Name { get; }
public int BreedId { get; }
}
public record DogEmbed(Breed Breed);
To provide a collection response like:
{
"_embedded": {
"dogs": [
{
"id": 1,
"name": "Bessie",
"breedId": 1,
"_links": {
"breed": {
"href": "/breed/1"
},
"self": {
"href": "/dog/1"
}
}
},
{
"id": 2,
"name": "Liva",
"breedId": 1,
"_links": {
"breed": {
"href": "/breed/1"
},
"self": {
"href": "/dog/2"
}
}
}
]
},
"_links": {
"find": {
"href": "/dog/{id}",
"templated": true
},
"self": {
"href": "/dog"
}
}
}
And an item reponse like:
{
"id": 1,
"name": "Bessie",
"breedId": 1,
"_embedded": {
"breed": {
"id": 1,
"name": "Boston Terrier",
"size": "Small",
"temperament": "Curious",
"_links": {
"self": {
"href": "/breed/1"
}
}
}
},
"_links": {
"breed": {
"href": "/breed/1"
},
"self": {
"href": "/dog/1"
}
}
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.1
- System.Text.Json (>= 6.0.10)
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 |
---|---|---|
1.0.0 | 42 | 2/3/2025 |
1.0.0-alpha | 36 | 2/3/2025 |