using HttpServer; var server = new HttpServer(); server.Add((context, next) => { context.Response.StatusCode = 200; context.Response.Write("Hello, world!"); return next(); }); server.Start();
using HttpServer; var server = new HttpServer(); server.Add((context, next) => { if (context.Request.Path == "/protected") { context.Response.StatusCode = 401; context.Response.Write("Unauthorized"); return Task.CompletedTask; } else { return next(); } }); server.Start();In this example, we add a middleware function that checks if the request path is "/protected". If it is, we return a 401 Unauthorized response. Otherwise, we call the next middleware in the pipeline. The HttpServer package library is most likely part of the Microsoft ASP.NET Core framework.