MinApiLib.Hypermedia 9.0.0

dotnet add package MinApiLib.Hypermedia --version 9.0.0                
NuGet\Install-Package MinApiLib.Hypermedia -Version 9.0.0                
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="MinApiLib.Hypermedia" Version="9.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MinApiLib.Hypermedia --version 9.0.0                
#r "nuget: MinApiLib.Hypermedia, 9.0.0"                
#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 MinApiLib.Hypermedia as a Cake Addin
#addin nuget:?package=MinApiLib.Hypermedia&version=9.0.0

// Install MinApiLib.Hypermedia as a Cake Tool
#tool nuget:?package=MinApiLib.Hypermedia&version=9.0.0                

license version

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 Compatible and additional computed target framework versions.
.NET 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.  net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.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
9.0.0 72 11/13/2024
8.0.1 120 4/11/2024
8.0.0 1,511 12/14/2023
7.0.4 2,084 5/17/2023
7.0.3 166 4/18/2023
7.0.2 218 3/22/2023
7.0.1 208 3/21/2023
7.0.0 272 2/14/2023
7.0.0-beta 173 11/10/2022