This repository was archived by the owner on Feb 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Quick start
Fernando Escolar edited this page May 6, 2021
·
1 revision
Create a new web project:
mkdir MyApp
cd MyApp
dotnet new webFirst of all, you have to add RoutingRecords package reference to your project:
dotnet add package RoutingRecordsThen you have two choices:
Delete all .cs files and add a new one with this content:
using RoutingRecords;
new ApiApp().Run();
record Hello() : Get("/", (req, res) =>
res.SendAsync("Hello World!"));And test your application:
dotnet runDisclaimer: this solution is great for quick little APIs. But its use is not recommended in production applications.
In the StartUp file you have to call AddRouteRecords in the ConfigureServices and MapRouteRecords in the enpoints mapping section:
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using RoutingRecords;
namespace SampleApp
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddRouteRecords(typeof(Startup).Assembly);
}
public void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseEndpoints(endpoints => endpoints.MapRouteRecords());
}
}
}Now you can create a new file with your route record:
using RoutingRecords;
namespace SampleApp.Api
{
public record Hello()
: Get("/", (req, res) =>
res.SendAsync("Hello World!"));
}Finally test your application:
dotnet run