HAL.AspNetCore
18.1.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package HAL.AspNetCore --version 18.1.1
NuGet\Install-Package HAL.AspNetCore -Version 18.1.1
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="HAL.AspNetCore" Version="18.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HAL.AspNetCore" Version="18.1.1" />
<PackageReference Include="HAL.AspNetCore" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HAL.AspNetCore --version 18.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: HAL.AspNetCore, 18.1.1"
#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.
#:package HAL.AspNetCore@18.1.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=HAL.AspNetCore&version=18.1.1
#tool nuget:?package=HAL.AspNetCore&version=18.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
HAL
This project aims to bring a simple to use implementation of the Hypertext Application language.
Specification
- The formal specification is published as in IETF draft and can be found under https://tools.ietf.org/html/draft-kelly-json-hal-08.
- A more informal documentation can be found under http://stateless.co/hal_specification.html.
- The specification of HAL-Forms can be found here: https://rwcbook.github.io/hal-forms/
Usage
The project consists of multiple packages
HAL.Commonwhich contains theResource,Resource<T>,FormsResource,FormsResource<T>andLinkimplementations and the converters needed for serialization withSystem.Text.Json.HAL.AspNetCoreaddsIResourceFactory,IFormFactoryandILinkFactorywhich can be used in your controllers to easily generate resources from your models. It also comes with aHalControllerBaseclass which can be used for all Controllers which return HAL.HAL.AspNetCore.ODataaddsIODataResourceFactoryandIODataFormFactorywhich can be used in your controllers to easily generate list endoints with paging from OData $filter, $skip and $top syntax.Hal.Client.Netis a client library to consume HAL APIs in .Net applications. When using it, you should callapp.Services.AddHalClientFactoy()to inject theIHalClientFactorywhich can then be resolved in your application.Hal.Client.Angular/@wertzui/ngx-hal-clientis a client library to consume HAL APIs in Angular applications. It exposes theHalClientModulewhich then provides theHalClientand aFormService.
Without OData support
In Program.cs
builder.Services
.AddControllers() // or .AddMvc()
.AddHal()
.AddJsonOptions(o => // not neccessary, but creates a much nicer output
{
o.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault;
});
In your controller
[Route("[controller]")]
public class MyController : HalControllerBase
{
private readonly IResourceFactory _resourceFactory;
public Table(IResourceFactory resourceFactory)
{
_resourceFactory = resourceFactory ?? throw new ArgumentNullException(nameof(resourceFactory));
}
[HttpGet]
[ApiConventionMethod(typeof(DefaultApiConventions), nameof(DefaultApiConventions.Get))]
public ActionResult<IResource> GetList()
{
var models = new[]
{
new MyModelListDto {Id = 1, Name = "Test1"},
new MyModelListDto {Id = 2, Name = "Test2"},
};
var result = _resourceFactory.CreateForListEndpoint(models, _ => "items", m => m.Id);
return Ok(result);
}
[HttpGet("{id}")]
public ActionResult<IResource<ModelFullDto>> Get(int id)
{
var model = new ModelFullDto { Id = id, Name = $"Test{id}", Description = "Very important!" };
var result = _resourceFactory.CreateForGetEndpoint(model);
return Ok(result);
}
// PUT, POST, ...
}
With OData support
In Program.cs with OData support
var modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<MyModelListDto>(typeof(MyModelListDto).Name);
builder.Services.AddSingleton(_ => modelBuilder.GetEdmModel());
builder.Services
.AddControllers(options => // or .AddMvc()
{
options.OutputFormatters.RemoveType<ODataOutputFormatter>();
options.InputFormatters.RemoveType<ODataInputFormatter>();
})
.AddOData()
.AddHALOData()
.AddJsonOptions(o => // not neccessary, but creates a much nicer output
{
o.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault;
});
}
var app = builder.Build();
app.UseRouting();
// ...
app.UseEndpoints(_ => { });
app.MapControllers();
}
In your controller with OData support
[Route("[controller]")]
public class MyController : HalControllerBase
{
private readonly IODataResourceFactory _resourceFactory;
public Table(IODataResourceFactory resourceFactory)
{
_resourceFactory = resourceFactory ?? throw new ArgumentNullException(nameof(resourceFactory));
}
[HttpGet]
[ApiConventionMethod(typeof(DefaultApiConventions), nameof(DefaultApiConventions.Get))]
public ActionResult<Resource> GetList(
// The SwaggerIgnore attribute and all parameters beside the options are just here to give you a nice swagger experience.
// If you do not need that, you can remove everything except the options parameter.
// If you are using RESTworld, you can also remove everything except the options parameter, because there is a custom Swagger filter for that.
[SwaggerIgnore] ODataQueryOptions<TEntity> options,
[FromQuery(Name = "$filter")] string? filter = default,
[FromQuery(Name = "$orderby")] string? orderby = default,
[FromQuery(Name = "$top")] long? top = default,
[FromQuery(Name = "$skip")] long? skip = default)
{
var models = new[]
{
new MyModelListDto { Id = 1, Name = "Test1" },
new MyModelListDto { Id = 2, Name = "Test2" },
};
// Apply the OData filtering
models = options.Apply(models.AsQueryable()).Cast<MyModelListDto>().ToArray()
var result = _resourceFactory.CreateForOdataListEndpointUsingSkipTopPaging(models, _ => "items", m => m.Id, options);
return Ok(result);
}
// GET, PUT, POST, ...
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Asp.Versioning.Abstractions (>= 8.1.0)
- HAL.Common (>= 8.1.0)
- Macross.Json.Extensions (>= 3.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on HAL.AspNetCore:
| Package | Downloads |
|---|---|
|
HAL.AspNetCore.OData
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 20.0.3 | 101 | 2/10/2026 |
| 20.0.2 | 108 | 2/9/2026 |
| 20.0.1 | 315 | 12/15/2025 |
| 20.0.0 | 476 | 11/11/2025 |
| 19.0.2 | 273 | 11/9/2025 |
| 19.0.1 | 268 | 11/9/2025 |
| 19.0.0 | 261 | 11/9/2025 |
| 18.2.1 | 440 | 9/16/2025 |
| 18.2.0 | 384 | 6/19/2025 |
| 18.1.1 | 366 | 4/15/2025 |
| 18.1.0 | 368 | 3/17/2025 |
| 18.0.1 | 427 | 1/26/2025 |
| 18.0.0 | 465 | 11/20/2024 |
| 17.2.2 | 2,675 | 11/6/2024 |
| 17.2.1 | 687 | 10/11/2024 |
| 17.2.0 | 409 | 9/27/2024 |
| 17.1.1 | 605 | 7/18/2024 |
| 17.1.0 | 485 | 7/3/2024 |
| 17.0.0 | 259 | 7/3/2024 |
| 16.0.0 | 284 | 7/2/2024 |
Loading failed