Skip to content

naice/Blazor.MinimalApi

Repository files navigation

Jens.AspNetCoreBackgroundJobs

Blazor.MinimalApi

x Release

This project aims to simplify Blazor Api Data requests and get rid of messy url definitions.

Blazor.MinimalApi.Server

Downloads

Download & Install

Nuget Package Blazor.MinimalApi.Server

Install-Package Blazor.MinimalApi.Server

Program.cs

// Add endpoint definitions
builder.Services.AddEndpointDefinitions(typeof(Program));

var app = builder.Build();
// ...
app.UseEndpointDefinitions();

SampleEndpointDefinition.cs

public class SampleEndpointDefinition : IEndpointDefinition
{
    public void DefineEndpoints(IEndpointRouteBuilder builder)
    {
        builder.MinimalMapGet<Car[]>(async ([FromQuery(Name = "count")] int count) =>
        {
            await Task.Delay(100);
            return new CarFaker().Generate(count);
        });
        builder.MinimalMapGet<CarsRequest, Car[]>((CarsRequest request) 
            => new CarFaker().Generate(request.Count));
        builder.MinimalMapQuery<CarsRequest, Car[]>((CarsRequest request) 
            => new CarFaker().Generate(request.Count));
    }
}

Blazor.MinimalApi.Client

Downloads

Download & Install

Nuget Package Blazor.MinimalApi.Client

Install-Package Blazor.MinimalApi.Client

Program.cs

// Add minimal api client
builder.Services.AddMinimalApiClient();

CarsRequestSample.razor

@page "/"
@using Blazor.MinimalApi.Model
@inject MinimalHttpClient<CarsRequest, Car[]> CarClient

<PageTitle>MinimalHttpClient&lt;CarsRequest, Car[]&gt; Sample</PageTitle>

<input type="number" @bind="_countCars" />
<input type="button" value="Load Cars" @onclick="LoadCars"/>   

<h1>Cars</h1>

@foreach (var car in _cars.OrderBy(c => c.Manufacturer))
{
    <div>
        <h4> @car.Manufacturer - @car.Model </h4>
        <strong>@car.Type</strong> - @car.Fuel<br/>
        <i>@car.Vin</i><br/>
        <hr/>
    </div>
}

@code{
    private int _countCars = 10;
    private Car[] _cars = Array.Empty<Car>();

    private async Task LoadCars()
    {
        _cars = await CarClient.Query(new CarsRequest(_countCars)) ?? Array.Empty<Car>();
    }
}

Blazor.MinimalApi.Abstractions

Downloads

Download & Install

Nuget Package Blazor.MinimalApi.Abstractions

Install-Package Blazor.MinimalApi.Client

Info

Main reason for the abstraction library is the IMinimalApiRouteProvider interface and it's default implementation MinimalApiDefaultRouteProvider. This interface is shared Client / Server side and used to build routes.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published