VHal.AspNetCore 1.0.0

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

// Install VHal.AspNetCore as a Cake Tool
#tool nuget:?package=VHal.AspNetCore&version=1.0.0                

Hal.AspNetCore

Hal.AspNetCore provides ASP.NET Core extensions for implementing Hypertext Application Language (HAL) in web APIs. This package integrates seamlessly with Hal.Core to offer a comprehensive solution for HAL-compliant API development.

Features

  • ASP.NET Core Integration: Smooth integration with ASP.NET Core, simplifying the creation of HAL resources.
  • Request Handling: Efficient handling of requests and responses within the HAL framework.
  • Resource Link Management: Streamlined link management for resource collections and individual resources.

Installation

Install the package via NuGet:

dotnet add package Hal.AspNetCore

Usage

Here's how to use Hal.AspNetCore in your ASP.NET Core application:

using Hal.AspNetCore;
using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route("api/[controller]")]
public class WeatherForecastController : ControllerBase
{
    private readonly ILinkGenerator linkGenerator;

    public WeatherForecastController(ILinkGenerator linkGenerator)
    {
        this.linkGenerator = linkGenerator;
    }

    [HttpGet]
    public IActionResult GetWeatherForecast()
    {
        var forecast = Enumerable.Range(1, 5).Select(index =>
            new WeatherForecast
            (
                DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
                Random.Shared.Next(-20, 55),
                summaries[Random.Shared.Next(summaries.Length)]
            ))
            .ToArray();

        var response = new ResourceCollectionBuilder<WeatherForecast, string>(forecast, "meta")
            .AddLink(linkBuilder =>
                linkBuilder
                .SetRel("self")
                .SetMethod(HttpVerbs.Get)
                .SetHref(linkGenerator.GenerateUri("GetWeatherForecastWithMeta", new { }))
                .Build())
            .AddLink(linkBuilder =>
                linkBuilder
                .SetRel("all")
                .SetMethod(HttpVerbs.Get)
                .SetHref(linkGenerator.GenerateUri("GetWeatherForecast", new { }))
                .Build())
            .Build();

        return Ok(response);
    }

    [HttpGet("{id}")]
    public IActionResult GetWeatherForecastById(int id)
    {
        var item = new WeatherForecast
        (
            DateOnly.FromDateTime(DateTime.Now.AddDays(id)),
            Random.Shared.Next(-20, 55),
            summaries[Random.Shared.Next(summaries.Length)]
        );

        var response = new ResourceBuilder<WeatherForecast>(item)
            .AddLink("self", linkGenerator.GenerateUri("GetLowest", new { }), HttpVerbs.Get)
            .AddLink("all", linkGenerator.GenerateUri("GetWeatherForecast", new { }), HttpVerbs.Get)
            .Build();

        return Ok(response);
    }
}

License

This project is licensed under the MIT License.

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.0 43 12/22/2024