MinApiLib.Hypermedia
8.0.1
See the version list below for details.
dotnet add package MinApiLib.Hypermedia --version 8.0.1
NuGet\Install-Package MinApiLib.Hypermedia -Version 8.0.1
<PackageReference Include="MinApiLib.Hypermedia" Version="8.0.1" />
paket add MinApiLib.Hypermedia --version 8.0.1
#r "nuget: MinApiLib.Hypermedia, 8.0.1"
// Install MinApiLib.Hypermedia as a Cake Addin #addin nuget:?package=MinApiLib.Hypermedia&version=8.0.1 // Install MinApiLib.Hypermedia as a Cake Tool #tool nuget:?package=MinApiLib.Hypermedia&version=8.0.1
MinApiLib.Hypermedia
This package contains extensions to use hypermedia in your projects.
Installation
You can install this package using the NuGet package manager:
Install-Package MinApiLib.Hypermedia
Or using the .NET CLI:
dotnet add package MinApiLib.Hypermedia
Usage
To use hypermedia, you need to add the following code in your Program.cs
:
global using MinApiLib.Hypermedia;
// ...
builder.Services.AddHypermedia();
// ...
app.MapEndpoints()
.WithHypermedia();
It will use "application/vnd.hypermedia+json" as default mime type, but you can change it by adding the contentType
parameter:
builder.Services.AddHypermedia(contentType: "application/vnd.my.format+json");
Then you should create your hypermedia providers for your response models:
public record struct Response(HashedId Id, string Name);
public class ResponseHypermediaProvider : HypermediaProvider<Response>
{
protected override IEnumerable<HypermediaLink> GetLinksFor(Response @object)
{
yield return new HypermediaLink("self", "/things/" + @object.Id, "GET");
yield return new HypermediaLink("update", "/things/" + @object.Id, "PUT");
yield return new HypermediaLink("delete", "/things/" + @object.Id, "DELETE");
yield return new HypermediaLink("beers", "/things", "GET");
}
}
public record GetThing() : GetEndpoint("/things/{id}")
{
public IResult Handle(int id)
=> Results.Ok(new Response(id, "John Doe"));
}
You should add "application/vnd.hypermedia+json" as "Accept" header in order to get hypermedia links:
$ curl -H "Accept: application/vnd.hypermedia+json" "http://localhost:5000/things/1"
{"value":{"id":"Wk","name":"John Doe"},"links":[{"href":"http://localhost:5000/things/Wk","rel":"self","method":"GET"},{"href":"http://localhost:5000/things/Wk","rel":"update","method":"PUT"},{"href":"http://localhost:5000/things/Wk","rel":"delete","method":"DELETE"},{"href":"http://localhost:5000/things","rel":"beers","method":"GET"}]}%
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 is compatible. 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.
-
net8.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.