O Language

Routing

Map HTTP methods and paths to responses in a webserver route table.

O Language pagesRouting
On this page

A route table is a hash keyed by path. Each route entry sets a type and a response. The response may be a string or a function.

def show_profile = fn(id) {
    return json({"id": id})
}

def routes = {
    "/profiles/:id": {
        "type": "GET",
        "response": show_profile
    }
}

webserver("10000", routes)

A handler’s route parameter is available through server.parameters. The runtime also exposes request headers, query values and submitted form values through the request-scoped server object. See Web programming for a full server example.

Methods and generated routes

The web CLI route generator accepts GET, POST, PUT, DELETE and PATCH. It writes entries directly to config/config.ola; the scaffold does not create a separate routes file. Creating a controller adds a generated GET route for it.

The server implementation also handles options for response headers and status, uploads and static folders. Those paths have their own option fields; consult the versioned server implementation before relying on advanced behavior.

Next