Skip to content
FutureBlitz

    Install

    Import std.net.http.routes

    std.net.http.routes

    Routes from a Class's Methods: each Async Method with an attribute of its method and path, like @Get("/users/:id"), becomes a route, whose one argument, a Struct of what the request gives, is made from the route's path parameters, the query, and a JSON body, by Load<T>, as the command line's arguments are; a request whose values don't fit is a 400.

    std/net/http/routes.fb

    Types

    Get attribute

    Public Attribute Get(Path: String)

    What a routes Class's Method answers: its method and path, a path as HttpRouter has them.

    std/net/http/routes.fb, line 16

    Post attribute

    Public Attribute Post(Path: String)

    A routes Class's Method that answers POST at Path.

    std/net/http/routes.fb, line 18

    Put attribute

    Public Attribute Put(Path: String)

    A routes Class's Method that answers PUT at Path.

    std/net/http/routes.fb, line 20

    Patch attribute

    Public Attribute Patch(Path: String)

    A routes Class's Method that answers PATCH at Path.

    std/net/http/routes.fb, line 22

    Delete attribute

    Public Attribute Delete(Path: String)

    A routes Class's Method that answers DELETE at Path.

    std/net/http/routes.fb, line 24

    JsonBody attribute

    Public Attribute JsonBody

    A route Struct's Field that's the request's body, read as JSON, and Load's to the Field's type.

    std/net/http/routes.fb, line 27

    Extends

    HttpRequest extend

    Extend HttpRequest Implements Loadable

    No doc comment.

    std/net/http/routes.fb, line 32

    • Public Static Method FromValue(value: Value): HttpRequest Throws ParseError static method #

      Makes one from a Value, as Load does.

      Doc from std.core.load.Loadable.FromValue.

    HttpRouter extend

    Extend HttpRouter

    No doc comment.

    std/net/http/routes.fb, line 39

    • @PanicsAtCaller Public Method Routes<T>(instance: T) method #

      Adds a route for each Async Method of instance's type with a @Get, @Post, @Put, @Patch, or @Delete, or several, which gives an HttpResponse and takes nothing, the request, one Struct or Class, or that and the request: @Get("/users/:id") Async Method Show(args: ShowUser): HttpResponse. Each call's Struct or Class is made by Load from an Object of its Fields' values: a path parameter or, failing that, a query parameter, whose name is the Field's, or its @Rename's, or else its @Renamed's old one, whatever the letters' case, as text, which Load reads as a number or a Bool where the Field is one; a @Flatten Field's own Fields, as Load reads them; and for a @JsonBody Field, the body's JSON. A Field the request doesn't give keeps its default, or zero, and one with neither, or a value that doesn't fit, or a body that isn't JSON, is a 400 that says why. Methods without one of those attributes are left alone, and so are Static Methods and those with a ByRef parameter, which no For Method loop goes over. Panics as Get does for a path, or a route with its paths already, and for a Method of up to four arguments with one that isn't a route's shape: one that isn't Async, throws, gives something else, takes the request first, or takes what Load doesn't make from an Object, like a number or an HttpRequest?.

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