HAL.Common 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package HAL.Common --version 1.1.0                
NuGet\Install-Package HAL.Common -Version 1.1.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="HAL.Common" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HAL.Common --version 1.1.0                
#r "nuget: HAL.Common, 1.1.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 HAL.Common as a Cake Addin
#addin nuget:?package=HAL.Common&version=1.1.0

// Install HAL.Common as a Cake Tool
#tool nuget:?package=HAL.Common&version=1.1.0                

HAL

This project aims to bring a simple to use implementation of the Hypertext Application language.

Specification

Usage

The project consists of two packages

  1. HAL.Common which contains the IResource, IResource<T> and ILink implementations and the converters needed for serialization with System.Text.Json.
  2. HAL.AspNetCore adds IResourceFactory and ILinkFactory which can be used in your controllers to easily generate resources from your models.

In Startup.cs

public void ConfigureServices(IServiceCollection services)
{
   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]")]
[ApiController]
public class MyController : ControllerBase
{
   private readonly IResourceFactory _resourceFactory;

   public Table(IResourceFactory resourceFactory)
   {
       _resourceFactory = resourceFactory ?? throw new ArgumentNullException(nameof(resourceFactory));
   }

   [HttpGet]
   public ActionResult<IResource> Get()
   {
       var models = new[]
       {
           new MyModelListDto {Id = 1, Name = "Test1"},
           new MyModelListDto {Id = 2, Name = "Test2"},
       };

       var result = _resourceFactory.CreateForListEndpoint(models, 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, ...
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on HAL.Common:

Package Downloads
HAL.AspNetCore

Package Description

RESTworld.Common

Package Description

HAL.Client.Net

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.1.1 281 10/11/2024
7.1.0 223 9/27/2024
7.0.0 596 7/2/2024
6.0.0 372 6/4/2024
5.2.0 873 1/9/2024
5.1.0 270 12/22/2023
5.0.0 853 11/14/2023
4.1.0 482 10/23/2023
4.0.0 477 9/26/2023
3.3.0 901 7/3/2023
3.2.2 1,233 6/14/2023
3.2.1 554 5/25/2023
3.2.0 888 4/30/2023
3.1.2 699 3/11/2023
3.1.1 810 2/22/2023
3.1.0 523 2/9/2023
3.0.1 1,122 12/12/2022
3.0.0 1,338 11/9/2022
2.3.1 2,149 10/20/2022
2.3.0 1,698 9/26/2022
2.2.1 4,030 6/8/2022
2.2.0 3,015 4/1/2022
2.1.0 3,907 3/30/2022
2.0.0 6,085 12/3/2021
1.5.0 4,478 11/24/2021
1.4.0 2,474 10/5/2021
1.3.3 1,247 9/7/2021
1.3.2 1,405 6/28/2021
1.3.1 676 5/10/2021
1.3.0 1,366 3/24/2021
1.2.0 712 1/27/2021
1.1.1 419 1/26/2021
1.1.0 492 1/20/2021
1.0.1 452 1/19/2021
1.0.0 444 1/17/2021