RecurLoop/ Documentation
Http/Guidesv0.2.12

Http

Build an IPv4 HTTP server with typed handlers, exact or prefix routes, bounded request parsing and a worker pool. Import http; route callbacks receive borrowed Http:Request* and Http:Response* arguments.

A small service

recurloop
import http
let serve_health = fn () -> i64 {
    http "127.0.0.1" 8080 {
        GET "/health" -> fn (request:Http:Request*, response:Http:Response*) -> void {
            response.json(200, "{\"status\":\"ok\"}")
        }
    }
    return 0
}
// Call serve_health() to start the blocking server.

The example defines the server without starting it. Serving blocks until the accept loop stops or fails. A handler should produce one response before returning; if it sends none, the server supplies an empty 204 response.

API map

NeedAPI
Declare routeshttp, Http:Server:route
Read headers or query valuesRequest:header, Request:param
Send text, HTML, JSON or bytesResponse:text, html, json, send
Limit work and memoryHttp:Limits, the limits clause
Serve one connectionhttp once, Server:serve_once

The response JSON helper sets a content type; it is not a serializer or JSON validator.

Learning path

  1. Routing — Register handlers in a deliberate matching order.
  2. Requests — Read and validate request data.
  3. Responses — Send one response with valid data lifetimes.
  4. Server lifecycle — Create, run and release the server.
  5. Limits — Bound request sizes, timeouts and concurrent work.