MinApiLib.HashedIds 8.0.0

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

// Install MinApiLib.HashedIds as a Cake Tool
#tool nuget:?package=MinApiLib.HashedIds&version=8.0.0                

license version

MinApiLib.HashedIds

This package contains extensions to use hashed ids in your endpoints. It uses the Hashids library.

Installation

You can install this package using the NuGet package manager:

Install-Package MinApiLib.HashedIds

Or using the .NET CLI:

dotnet add package MinApiLib.HashedIds

Usage

To use hashed ids, you can add the AddHashedIds method in your Program.cs file:

global using MinApiLib.HashedIds;
// ...
builder.Services.AddHashedIds(op => op.Passphrase = "my secret passphrase");

Then, you can use the HashedId type in your endpoints:

public record struct Response(HashedId Id, string Name);

public record Get() : GetEndpoint("/things")
{
    public IResult Handle()
        => Results.Ok(new Response(1, "John Doe"));
}

And test it with curl:

$ curl "http://localhost:5000/things"
{"id":"Wd","name":"John Doe"}%

You can also use the HashedId type in your requests and responses:

public record struct Request(HashedId Id, CancellationToken CancellationToken);

public record struct Response(HashedId Id, string Name);

public record GetThing() : GetEndpoint<Request>("/things/{id}")
{
    protected override Task<IResult> OnHandleAsync(Request request, CancellationToken cancellationToken)
    {
        int id = request.Id;
        var response = new Response(id, "John Doe");
        return Task.FromResult(Results.Ok(response));
    }
}

And test it:

$ curl "http://localhost:5000/things/Wd"
{"id":"Wd","name":"John Doe"}%
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
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
9.0.0 72 11/13/2024
8.0.1 143 4/11/2024
8.0.0 689 12/14/2023
7.0.4 950 5/17/2023
7.0.3 174 4/18/2023
7.0.2 224 3/22/2023
7.0.1 215 3/21/2023
7.0.0 261 2/14/2023
7.0.0-beta 178 11/10/2022