O Language/Web

From OnixOS

Web Programming

O Language includes an HTTP server runtime. This section explains web programming concepts; O Language Web Framework explains project scaffolding and the olf conventions.

Start an HTTP server

Pass a port and a route hash to webserver:

def config = {
  "/": {"type": "GET", "response": "Welcome!"}
}

webserver("8080", config)

Handle requests

A route response can be a function. Path parameters are available through the request context.

def hello = fn(name) {
  return json({"message": ("Hello, " + name + "!")})
}

def config = {
  "/hello/:name": {"type": "GET", "response": hello}
}

webserver("8080", config)

The request-scoped server value provides headers, get, post, parameters, form, and response.

Continue with web development

  • Routing explains route definitions and generated routes.
  • Database explains connections, models, migrations, and queries.
  • O Language Web Framework explains how to create and run a complete project.