Skip to content
FutureBlitz

    Install

    Import std.net.http.server

    HttpRouter

    std.net.http.server

    class

    Public Class HttpRouter

    Routes, and the middleware around them: a server's own, or a group's, whose routes' paths start with its prefix and whose middleware runs inside its parent's. A path is segments after a '/' each: text, which the request's segment matches when it's the same once it's percent-decoded, :name, which matches any one segment and binds it to name, or, last, *name, which matches the rest of the path, empty too, and binds it. Of the routes whose paths match a request's, the one whose segments are text first, segment by segment, takes it, and of those its method fits, the first added; a request whose path some route matches but whose method none has is a 405 Method Not Allowed, and one whose path none matches a 404. A HEAD goes to a GET's route when there's no HEAD's, and its response's body isn't sent.

    std/net/http/server.fb, line 250

    • @PanicsAtCaller Public Method Get(path: String, handler: HttpHandler) method #

      Adds a route for GET and the path, which panics unless it's a path as HttpRouter has them, or another route has the method and a path that matches what it matches.

    • @PanicsAtCaller Public Method Post(path: String, handler: HttpHandler) method #

      Adds a route for POST and path, as Get does.

    • @PanicsAtCaller Public Method Put(path: String, handler: HttpHandler) method #

      Adds a route for PUT and path, as Get does.

    • @PanicsAtCaller Public Method Patch(path: String, handler: HttpHandler) method #

      Adds a route for PATCH and path, as Get does.

    • @PanicsAtCaller Public Method Delete(path: String, handler: HttpHandler) method #

      Adds a route for DELETE and path, as Get does.

    • @PanicsAtCaller Public Method Route(method: String, path: String, handler: HttpHandler) method #

      Adds a route for method, any token, like "PROPFIND", as Get does.

    • @PanicsAtCaller Public Method Work(path: String, handler: WorkHandler) method #

      Adds a work route for GET and the path, as Get does, whose handler blocks, computing or waiting, and so runs on one of the server's Workers threads, given a Sendable copy of the request, while the main thread goes on answering others. The server's and groups' middleware runs around it on the main thread, as it does around any route.

    • @PanicsAtCaller Public Method Work(method: String, path: String, handler: WorkHandler) method #

      Adds a work route for method, as Route does.

    • Public Method Use(middleware: HttpMiddleware) method #

      Adds middleware, which runs around each of its routes' handlers, after what Use gave it before, a server's around every request, the ones no route takes too.

    • @PanicsAtCaller Public Method Group(prefix: String): HttpRouter method #

      A group of routes whose paths start with prefix, a path as routes have them, but without a *name, or it panics, and whose middleware runs inside this one's.

    Report an issue with this page or with FutureBlitz on GitHub.