AspNetCore.Hateoas
1.0.0
dotnet add package AspNetCore.Hateoas --version 1.0.0
NuGet\Install-Package AspNetCore.Hateoas -Version 1.0.0
<PackageReference Include="AspNetCore.Hateoas" Version="1.0.0" />
paket add AspNetCore.Hateoas --version 1.0.0
#r "nuget: AspNetCore.Hateoas, 1.0.0"
// Install AspNetCore.Hateoas as a Cake Addin #addin nuget:?package=AspNetCore.Hateoas&version=1.0.0 // Install AspNetCore.Hateoas as a Cake Tool #tool nuget:?package=AspNetCore.Hateoas&version=1.0.0
HATEOAS for ASP.NET Core MVC
This adds simple HATEOAS with JSON support for ASP.NET Core MVC applications.
Getting started
The JSON HATEOAS provider extends the IMvcBuilder
and is used like the following:
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvc()
.AddHateoas(...);
//other services
}
Making a request to one of the APIs in your application with Accept
header set as application/json+hateoas
, will return the HATEOAS payload containing the expected resource(s).
Example
Given the following DTO in your application:
public class PersonDto
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
With the following Controller:
[Route("api/[controller]")]
public class PeopleController : Controller
{
[HttpGet(Name = "get-people")]
public IActionResult Get() {...}
[HttpGet("{id}", Name = "get-person")]
public IActionResult Get(int id) {...}
[HttpPost(Name = "create-person")]
public IActionResult Post([FromBody]PersonDto person) {...}
[HttpPut("{id}", Name = "update-person")]
public IActionResult Put(int id, [FromBody]PersonDto person) {...}
[HttpDelete("{id}", Name = "delete-person")]
public IActionResult Delete(int id) {...}
}
Wire up HATEOAS with the particular links:
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvc()
.AddHateoas(options =>
{
options
.AddLink<PersonDto>("get-person", p => new { id = p.Id })
.AddLink<List<PersonDto>>("create-person")
.AddLink<PersonDto>("update-person", p => new { id = p.Id })
.AddLink<PersonDto>("delete-person", p => new { id = p.Id });
});
//other services
}
And executing this request:
GET /api/people HTTP/1.1
Accept: application/json+hateoas
Will result in the following response:
{
"_links": [
{
"href": "http://localhost:52691/api/people",
"rel": "create-person",
"method": "POST"
}
],
"items": [
{
"_links": [
{
"href": "http://localhost:52691/api/people/1",
"rel": "get-person",
"method": "GET"
},
{
"href": "http://localhost:52691/api/people/1",
"rel": "update-person",
"method": "PUT"
},
{
"href": "http://localhost:52691/api/people/1",
"rel": "delete-person",
"method": "DELETE"
}
],
"data": {
"id": 1,
"name": "Fanie",
"email": "fanie@mail.com"
}
},
{
"_links": [
{
"href": "http://localhost:52691/api/people/2",
"rel": "get-person",
"method": "GET"
},
{
"href": "http://localhost:52691/api/people/2",
"rel": "update-person",
"method": "PUT"
},
{
"href": "http://localhost:52691/api/people/2",
"rel": "delete-person",
"method": "DELETE"
}
],
"data": {
"id": 2,
"name": "Maarten",
"email": "maarten@example.com"
}
},
{
"_links": [
{
"href": "http://localhost:52691/api/people/2",
"rel": "get-person",
"method": "GET"
},
{
"href": "http://localhost:52691/api/people/2",
"rel": "update-person",
"method": "PUT"
},
{
"href": "http://localhost:52691/api/people/2",
"rel": "delete-person",
"method": "DELETE"
}
],
"data": {
"id": 2,
"name": "Marcel",
"email": "marcel@example.com"
}
}
]
}
```
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. |
.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
- Microsoft.AspNetCore.Mvc.Core (>= 2.0.1)
- Newtonsoft.Json (>= 10.0.3)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on AspNetCore.Hateoas:
Package | Downloads |
---|---|
Atomiv.Web.AspNetCore
Implementation of RESTful Services using ASP.NET Core |
|
Optivem.Framework.Web.AspNetCore
Implementation of RESTful Services using ASP.NET Core |
|
Optivem.Atomiv.Web.AspNetCore
Implementation of RESTful Services using ASP.NET Core |
|
Optivem.Web.AspNetCore
Implementation of RESTful Services using ASP.NET Core |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 27,834 | 5/23/2018 |