BitzArt.Flux.Rest
0.3.2-Prerelease
Prefix Reserved
This is a prerelease version of BitzArt.Flux.Rest.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package BitzArt.Flux.Rest --version 0.3.2-Prerelease
NuGet\Install-Package BitzArt.Flux.Rest -Version 0.3.2-Prerelease
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="BitzArt.Flux.Rest" Version="0.3.2-Prerelease" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BitzArt.Flux.Rest --version 0.3.2-Prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BitzArt.Flux.Rest, 0.3.2-Prerelease"
#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 BitzArt.Flux.Rest as a Cake Addin #addin nuget:?package=BitzArt.Flux.Rest&version=0.3.2-Prerelease&prerelease // Install BitzArt.Flux.Rest as a Cake Tool #tool nuget:?package=BitzArt.Flux.Rest&version=0.3.2-Prerelease&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Flux.REST
Installation
To use a REST client in your project, add the nuget package (The package is currently prerelease)
dotnet add package BitzArt.Flux.REST --prerelease
Usage
Configure Flux
services.AddFlux(flux =>
{
flux.AddService("service1") // Give your external service a specific name
.UsingRest("https://test.com") // External service's base url
.AddEntity<YourEntity>() // Adds an Entity of a specific type
.WithEndpoint("entity"); // Entity endpoint : https://test.com/entity
});
Use IFluxContext in your app
- Resolve
IFluxContext
from your DI container
serviceProvider.GetRequiredService<IFluxContext>();
- Get your entity context
var entityContext = fluxContext.Entity<YourEntity>()
- Use the IEntityContext to interact with this entity:
var entity = await entityContext.GetAsync(1); // Will make an http request to https://test.com/entity/1
var list = await entityContext.GetAllAsync(); // Will make an http request to https://test.com/entity
var page = await entityContext.GetPageAsync(0, 10); // Will make an http request to https://test.com/entity?offset=0&limit=10
Advanced scenarios
Entity endpoint configuration
WithEndpoint("your-entity-endpoint") // Sets the entity REST endpoint, e.g. https://test.com/your-entity-endpoint
WithIdEndpoint((key) => $"something/{key}") // Sets the entity ID endpoint, e.g. https://test.com/something/1
WithPageEndpoint("your-page-endpoint") // Sets the entity Page endpoint, e.g. https://test.com/your-page-endpoint
Custom variables
You can add custom variables to your endpoint configurations:
services.AddFlux(flux =>
{
flux.AddService("service1")
.UsingRest("https://test.com")
.AddEntity<YourEntity>()
.WithEndpoint("{a}/{b}");
});
Provide variable values when calling an appropriate method:
var a = "first";
var b = "second";
var entity = await entityContext.GetAsync(1, a, b); // Will make an http request to https://test.com/first/second/1
Custom Page endpoint with parent id example:
Flux configuration:
services.AddFlux(flux =>
{
flux.AddService("service1")
.UsingRest("https://test.com")
.AddEntity<Book>()
.WithPageEndpoint("authors/{authorId}/books");
});
Usage:
var books = fluxContext.Entity<Book>();
var authorId = 15;
var booksPage = await books.GetPage(0, 10, authorId); // https://test.com/authors/15/books?offset=0&limit=10
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
- BitzArt.Flux (>= 0.3.2-Prerelease)
- Microsoft.Extensions.Http (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.