Introduction

Flux.REST is a REST client implementation for the Flux package.

We recommend reviewing the Flux documentation first.

Installation

To use a REST client in your project, add the nuget package (currently in prerelease state)

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
    .AddSet<YourModel>()            // Adds a Set for a specific model
        .WithEndpoint("model");     // Set endpoint : https://test.com/model
});

Refer to the Configuring Endpoints section for more information on configuring endpoints for your external APIs.

Use IFluxContext in your app

  1. Resolve IFluxContext from your DI container
serviceProvider.GetRequiredService<IFluxContext>();
  1. Get your set context
// Resolve the Set directly
var setContext = fluxContext.Set<YourModel>();

// Or specify the external service
var setContext = fluxContext.Service("service1").Set<YourModel>();

ℹ️ Selecting a specific service can be useful in situations where you have multiple external services configured with the same model types.

  1. Use the SetContext to interact with this Set:
var model = await setContext.GetAsync(1); // Will make an http request to https://test.com/model/1

var list = await setContext.GetAllAsync(); // Will make an http request to https://test.com/model

var page = await setContext.GetPageAsync(0, 10); // Will make an http request to https://test.com/model?offset=0&limit=10

Refer to the Pagination section for more information on using and customizing pagination.