Layouting
Live on this serverRoutes requests to the handlers an application is made of.
using GenHTTP.Api.Content;
using GenHTTP.Modules.Files;
using GenHTTP.Modules.Functional;
using GenHTTP.Modules.Layouting;
public static class LayoutingSample
{
public static IHandlerBuilder Create()
{
/*
*
* Layouts allow you to structure your web application and divide it into
* different logical parts. The layout will route incoming requests to the designated
* handler. Layouts can be nested as needed.
*
* See https://genhttp.org/documentation/content/handlers/layouting/
*
*/
// serve the files shipped with this website (resources/samples/files),
// use Assets.From("./") to serve a directory
var assets = Assets.From(Resources.Tree("samples/files"));
// define a simple REST API
var api = Inline.Create()
.Get(() => "Hello World!");
// assemble our application from the parts above and
// register them at the given URLs
return Layout.Create()
.Add("assets", assets) // e.g. GET /samples/layouting/assets/README.md
.Add("api", api); // e.g. GET /samples/layouting/api/
}
}Try it
Send the requests to the sample running on this server - change the path, headers or body as you like, or copy them as curl commands.
Call the API
curl -i 'https://genhttp.org/samples/layouting/api/'Fetch a file
curl -i 'https://genhttp.org/samples/layouting/assets/README.md'