F23.Hateoas
2.0.0
dotnet add package F23.Hateoas --version 2.0.0
NuGet\Install-Package F23.Hateoas -Version 2.0.0
<PackageReference Include="F23.Hateoas" Version="2.0.0" />
<PackageVersion Include="F23.Hateoas" Version="2.0.0" />
<PackageReference Include="F23.Hateoas" />
paket add F23.Hateoas --version 2.0.0
#r "nuget: F23.Hateoas, 2.0.0"
#addin nuget:?package=F23.Hateoas&version=2.0.0
#tool nuget:?package=F23.Hateoas&version=2.0.0
F23.Hateoas
F23.Hateoas is a simple .NET library for working with HATEOAS (Hypermedia as the Engine of Application State) in ASP.NET Core applications. It provides a set of types that can be used to ensure consistent API responses containing optional hypermedia links.
Installation
You can install the library via NuGet Package Manager Console:
dotnet add package F23.Hateoas
or by adding a <PackageReference>
to your project file.
Usage
Wrap all your API response objects with HypermediaResponse
. This will allow you to add hypermedia links to the response if desired, but also acts as a consistent base response type for your API.
[HttpGet]
public IActionResult Get()
{
var data = ... // Fetch your data
return Ok(new HypermediaResponse(data)
{
Links = [
new HypermediaLink("self", "/api/sample"),
...
]
});
}
You might also find it helpful to create a helper method in a controller base class to simplify the creation of hypermedia responses:
public class MyBaseController : ControllerBase
{
protected IActionResult HypermediaOk(object content, IList<HypermediaLink>? links = null)
{
return Ok(new HypermediaResponse(content) { Links = links });
}
}
Then you can use it in your controllers like this:
[HttpGet]
public IActionResult Get()
{
var data = ... // Fetch your data
return HypermediaOk(data, [
new HypermediaLink("self", "/api/sample"),
...
]);
}
Contributing
This package is very minimalistic and is not likely to need many updates. If you have a feature request or bug report, please file a GitHub issue. Once accepted by our team, you may submit a pull request. PRs without an accepted issue have a higher likelihood of being rejected.
Migrating from v1 to v2
Version 2.0.0 of this library introduced a breaking change by removing the Newtonsoft.Json dependency.
If you need Newtonsoft.Json support, add a reference to the F23.Hateoas.NewtonsoftJson
package
and register the HypermediaResponseJsonConverter
and HypermediaLinkJsonConverter
with your JsonSerializerSettings
.
For example, in ASP.NET Core startup:
using F23.Hateoas.NewtonsoftJson;
...
builder.Services.AddControllers()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.Converters.Add(new HypermediaResponseJsonConverter());
options.SerializerSettings.Converters.Add(new HypermediaLinkJsonConverter());
});
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 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 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- System.Text.Json (>= 8.0.5)
-
net8.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on F23.Hateoas:
Package | Downloads |
---|---|
F23.ODataLite
A lightweight implementation of some OData operations for ASP.NET Core APIs. |
|
F23.Kernel.AspNetCore
Package Description |
|
F23.Hateoas.NewtonsoftJson
Newtonsoft.Json support for F23.Hateoas. |
GitHub repositories
This package is not used by any popular GitHub repositories.