Last active
February 21, 2021 19:08
-
-
Save OldWarrior3000/ec14a3bad9e633bd202a6590f66456db to your computer and use it in GitHub Desktop.
Revisions
-
OldWarrior3000 renamed this gist
Feb 21, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
OldWarrior3000 renamed this gist
Feb 21, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
OldWarrior3000 revised this gist
Feb 21, 2021 . No changes.There are no files selected for viewing
-
OldWarrior3000 created this gist
Feb 21, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; // with endpoint routing and JSON endpoints // see https://github.com/dotnet/aspnetcore/pull/23496/ for more on the JSON helpers WebHost.CreateDefaultBuilder(). ConfigureServices(s => s.AddSingleton<ContactService>()). Configure(app => { app.UseRouting(); app.UseEndpoints(e => { var contactService = e.ServiceProvider.GetRequiredService<ContactService>(); e.MapGet("/contacts", async c => await c.Response.WriteAsJsonAsync(await contactService.GetAll())); e.MapGet("/contacts/{id:int}", async c => await c.Response.WriteAsJsonAsync(await contactService.Get(int.Parse((string)c.Request.RouteValues["id"])))); e.MapPost("/contacts", async c => { await contactService.Add(await c.Request.ReadFromJsonAsync<Contact>()); c.Response.StatusCode = 201; }); e.MapDelete("/contacts/{id:int}", async c => { await contactService.Delete(int.Parse((string)c.Request.RouteValues["id"])); c.Response.StatusCode = 204; }); }); }).Build().Run();