Request Object

Inside route handlers, a req object is automatically available. It provides information about the incoming HTTP request.

Properties

Property Type Description
req.path String The request URI path, e.g. "/hello"
req.method String The HTTP method, e.g. "GET"

Usage

server 8080 {
    get "/info" {
        respond "Path: " + req.path
    }

    get "/method" {
        respond req.method
    }
}

Requesting /info returns Path: /info. Requesting /method returns GET.

Using req.path in responses

A common pattern is echoing the request path back in the response:

server 8080 {
    get "/hello" {
        respond req.path
    }
}

This returns the string /hello.

Limitations

The req object currently only exposes path and method. The following are not available:

  • Request headers
  • Query parameters
  • Request body
  • Cookies

Note: req is only available inside route handler blocks. Referencing it outside a get block will result in None.