-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
36 lines (25 loc) · 1.24 KB
/
Program.cs
File metadata and controls
36 lines (25 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using Microsoft.AspNetCore.Http.Json;
using MinimalWebApi;
using System.Text.Json.Serialization;
using static Microsoft.AspNetCore.Http.Results;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddHttpContextAccessor();
builder.Services.AddFreeAwait();
builder.Services.AddCors(options =>
options.AddDefaultPolicy(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));
builder.Services.AddSingleton<MinimalWebApi.Store>();
builder.Services.Configure<JsonOptions>(
options => options.SerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull);
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
app.UseCors();
// Map API endpoints
app.MapGet("/api/todos", () => Extensions.Run(Api.Get()));
app.MapGet("/api/todos/{id}", (int id) => Extensions.Run(Api.Get(id)));
app.MapPost("/api/todos", (Create create) => Extensions.Run(Api.Post(create)));
app.MapDelete("/api/todos", () => Extensions.Run(Api.Delete()));
app.MapDelete("/api/todos/{id}", (int id) => Extensions.Run(Api.Delete(id)));
app.MapMethods("/api/todos/{id}", new[] { "PATCH" }, (int id, Patch patch) => Extensions.Run(Api.Patch(id, patch)));
app.Run();