Examples

An HTTP server

Routes, handlers, and a listening loop, in twelve lines.

main (http/app, http, os)

# A complete HTTP server. Handlers borrow the request and return a
# response; route answers on a match and ?: falls through.
hello(req &app.request) http.response
    app.html(200, "<h1>Hello, np.</h1>")

json(req &app.request) http.response
    app.json(<ok = true, language = "np">)

routes(req &app.request) http.response
    req.route("GET /", hello) ?: req.route("GET /health", json) ?: req.notFound()

main()
    os.exit(app.serve(8080, routes))