O Language/Web/Routing

From OnixOS
Revision as of 07:20, 25 August 2026 by Tedaryum (talk | contribs) (Created page with "= Routing = Routes are stored as a hash passed to <code>webserver</code>. A route maps a path to an HTTP method and a response. <pre> def show_user = fn(id) { return json({"id": id}) } def config = { "/users/:id": { "type": "GET", "response": show_user } } </pre> Supported route types include <code>GET</code>, <code>POST</code>, <code>PUT</code>, <code>DELETE</code>, <code>PATCH</code>, <code>OPTIONS</code>, <code>UPLOAD</code>, and <code>STATIC</code>....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Routing

Routes are stored as a hash passed to webserver. A route maps a path to an HTTP method and a response.

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

def config = {
  "/users/:id": {
    "type": "GET",
    "response": show_user
  }
}

Supported route types include GET, POST, PUT, DELETE, PATCH, OPTIONS, UPLOAD, and STATIC.

Generated routes

In a web project, olang web create route writes routes directly to config/config.ola. It does not create a separate routes file. Creating a controller also adds its route and leaves the generated function empty for the developer to implement.