Static Files

Live on this server

Serves files from a directory or resource tree.

StaticFileSample.cs24 lines
using GenHTTP.Api.Content;

using GenHTTP.Modules.Files;

public static class StaticFileSample
{

    public static IHandlerBuilder Create()
    {
        /*
         *
         * Serves files from a given directory or resource tree.
         *
         * See https://genhttp.org/documentation/content/handlers/files/
         *
         */

        // serves the files shipped with this website (resources/samples/files),
        // use Assets.From("./") to serve a directory
        // e.g. GET /samples/static-files/README.md
        return Assets.From(Resources.Tree("samples/files"));
    }

}

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.

  1. Fetch a file

    GET
    curl -i 'https://genhttp.org/samples/static-files/README.md'
  2. Fetch another one

    GET
    curl -i 'https://genhttp.org/samples/static-files/books.csv'