Skip to content

Application

[Source]

The public API for the Hobby web framework.

Register routes via .> method chaining (get, post, etc.), then call serve() to freeze the routes and start listening.

use hobby = "hobby"
use stallion = "stallion"
use lori = "lori"

actor Main
  new create(env: Env) =>
    let auth = lori.TCPListenAuth(env.root)
    hobby.Application
      .>get("/", HelloHandler)
      .>get("/greet/:name", GreetHandler)
      .serve(auth, stallion.ServerConfig("localhost", "8080"), env.out)

Route methods are fun ref — automatic receiver recovery allows calling them on an iso receiver since all arguments are val. Use .> to chain route calls (it discards the method's return and passes the receiver through). Call .serve() last — it consumes the Application and freezes the routes.

class iso Application

Constructors

create

[Source]

new iso create()
: Application iso^

Returns


Public Functions

get

[Source]

Register a GET route.

fun ref get(
  path: String val,
  handler: Handler val,
  middleware: (Array[Middleware val] val | None val) = reference)
: None val

Parameters

Returns


post

[Source]

Register a POST route.

fun ref post(
  path: String val,
  handler: Handler val,
  middleware: (Array[Middleware val] val | None val) = reference)
: None val

Parameters

Returns


put

[Source]

Register a PUT route.

fun ref put(
  path: String val,
  handler: Handler val,
  middleware: (Array[Middleware val] val | None val) = reference)
: None val

Parameters

Returns


delete

[Source]

Register a DELETE route.

fun ref delete(
  path: String val,
  handler: Handler val,
  middleware: (Array[Middleware val] val | None val) = reference)
: None val

Parameters

Returns


patch

[Source]

Register a PATCH route.

fun ref patch(
  path: String val,
  handler: Handler val,
  middleware: (Array[Middleware val] val | None val) = reference)
: None val

Parameters

Returns


[Source]

Register a HEAD route.

fun ref head(
  path: String val,
  handler: Handler val,
  middleware: (Array[Middleware val] val | None val) = reference)
: None val

Parameters

Returns


options

[Source]

Register an OPTIONS route.

fun ref options(
  path: String val,
  handler: Handler val,
  middleware: (Array[Middleware val] val | None val) = reference)
: None val

Parameters

Returns


route

[Source]

Register a route with an arbitrary HTTP method.

fun ref route(
  method: Method val,
  path: String val,
  handler: Handler val,
  middleware: (Array[Middleware val] val | None val) = reference)
: None val

Parameters

Returns


add_middleware

[Source]

Add application-level middleware that runs before every route's middleware.

Can be called multiple times — middleware accumulates in registration order. Application middleware runs before group middleware, which runs before per-route middleware.

fun ref add_middleware(
  middleware: Array[Middleware val] val)
: None val

Parameters

Returns


group

[Source]

Consume a route group, flattening its routes into this application.

The group's prefix and middleware are applied to each of its routes. The group is consumed — no further registration on it is possible.

fun ref group(
  g: RouteGroup iso)
: None val

Parameters

Returns


serve

[Source]

Freeze routes and start listening for HTTP connections.

Consumes the Application — no further route registration is possible after this call.

fun iso serve(
  auth: TCPListenAuth val,
  config: ServerConfig val,
  out: OutStream tag)
: None val

Parameters

Returns