This is a .NET item template to ease the process of complying with the internal API guidelines in Monstarlab outlined in the (API Manifesto)[].
Newtonsoft.Json
FluentValidation.AspNetCore
- Pull repo
- In your terminal go to ./working/content
- type
dotnet new install ./
to install the item template - To create a new web project create an empty folder, navigate the terminal there and type
dotnet new web
. - Apply the template by typing
dotnet new mlapi -P Acme
. The-P
parameter is your project's name. It will replace a placeholder in various places in the item template. - Install dependency
dotnet add package FluentValidation.AspNetCore
- Install dependency
dotnet add package Newtonsoft.Json
- Configure the webproject to use the included custom exception handler and create initial routes for testing, eg. in ./Program.cs:
using Acme.Api.Exceptions;
using Acme.Api.Middleware.Helpers;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseCustomExceptionHandler(true);
app.MapGet("/", () => "Hello World!");
app.MapGet("/unauthorized", () => {
throw new AcmeUnauthorizedAccessApiException("Unauthorized message");
});
app.MapGet("/notfound", () => {
throw new AcmeNotFoundApiException("Not Found message");
});
app.Run();
dotnet build
dotnet run
- Test the endpoints in your browser.