MinApiLib.HashedIds
7.0.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 MinApiLib.HashedIds --version 7.0.1
NuGet\Install-Package MinApiLib.HashedIds -Version 7.0.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="MinApiLib.HashedIds" Version="7.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MinApiLib.HashedIds --version 7.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MinApiLib.HashedIds, 7.0.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.
// Install MinApiLib.HashedIds as a Cake Addin #addin nuget:?package=MinApiLib.HashedIds&version=7.0.1 // Install MinApiLib.HashedIds as a Cake Tool #tool nuget:?package=MinApiLib.HashedIds&version=7.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | Versions 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 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.
-
net7.0
- Hashids.net (>= 1.6.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.