This repo is no longer supported and will not receive any updates nor bug fixes, This code has been moved to the main Liquid repository and will be maintained there.
This repository is part of the Liquid Application Framework, a modern Dotnet Core Application Framework for building cloud native microservices.
This package contains the web api subsystem of Liquid, along with Http and GRPC implementation using Mediatr. In order to use it, add the main package (Liquid.WebApi.Http or Liquid.WebApi.Grpc) to your project, along with the specific implementation that you will need.
Liquid Application Framework - Web API base classes and supported cartridges
Available Cartridges | Badges |
---|---|
Liquid.WebApi.Grpc | |
Liquid.WebApi.Http |
This is a sample usage with Http cartridge
To create web api's using Liquid Application Framework you shoud create you domain command handlers, using Liquid.Domain. See a fast track guide on getting started.
With your domain command handlers implemented, you just need to implement LiquidControllerBase inheritance, and define actions for your handlers as exemplified :
using Liquid.WebApi.Http.Controllers;
using MediatR;
public class SampleController : LiquidControllerBase
{
public SampleController(IMediator mediator) : base(mediator)
{
}
[HttpGet("Sample")]
public async Task<IActionResult> Get() => await ExecuteAsync(new SampleRequest(), HttpStatusCode.OK);
}
To register domain handlers, liquid configurations, and all Liquid resources services, call dependency injection extension method in the Startup.cs class
public void ConfigureServices(IServiceCollection services)
{
services.AddLiquidHttp(typeof(SampleRequest).Assembly);
}
To use liquid middlewares for scoped logging and context, swagger, exception handler and culture, call ApplicationBuilder extension method:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseLiquidConfigure();
}
Once the startup and builder is configured using the extension methods as above, it will be necessary to set Liquid default configuration.
sample using file provider
{
"Liquid": {
"swagger": {
"name": "v1",
"host": "",
"schemes": [ "http", "https" ],
"title": "Liquidv2.SimpleApi",
"version": "v1",
"description": "Simple WebApi Sample.",
"SwaggerEndpoint": {
"url": "/swagger/v1/swagger.json",
"name": "SimpleWebApiSample"
}
},
//set default thread culture, considering that the culture middleware prioritizes the culture informed in the request.
"culture": {
"defaultCulture": "pt-BR"
},
//Set context keys that context middleware should obtain from request and set as scoped context.
"httpScopedContext": {
"keys": [
{
"keyName": "Connection",
"required": true
}
]
},
//Set keys that logging middleware should obtain from request and set as scoped logging header.
"HttpScopedLogging": {
"keys": [
{
"keyName": "Connection",
"required": true
}
]
}
}
}