public void Configure(IApplicationBuilder app) { var jokeProvider = new FileSystemJokeProvider(); app.Run(async context => { context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.ContentType = "application/json"; await context.Response.WriteAsync(await GetSerializedJoke(jokeProvider), Encoding.UTF8); }); }
public void Configure(IApplicationBuilder app) { FileSystemJokeProvider jokeProvider = new FileSystemJokeProvider(); app.Use(async(context, next) => { // Wir führen den Request aus await next(); // und verzögern die Antwort await Task.Delay(TimeSpan.FromSeconds(2)); }); app.Run(async context => { context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.ContentType = "application/json"; await context.Response.WriteAsync(await GetSerializedJoke(jokeProvider), Encoding.UTF8); }); }
public void Configure(IApplicationBuilder app) { FileSystemJokeProvider jokeProvider = new FileSystemJokeProvider(); RouteBuilder routes = new RouteBuilder(app); routes.MapGet("api/jokes/random", async context => { context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.ContentType = "application/json"; await context.Response.WriteAsync(await GetSerializedJoke(jokeProvider), Encoding.UTF8); }); routes.MapGet("{*path}", context => { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return(context.Response.WriteAsync("Well, IT'S YOUR FAULT!")); }); app.UseRouter(routes.Build()); }