Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Request Object

Route handlers receive an Uzumibi::Request as req.

PropertyValue
req.methodHTTP method String
req.pathRequest pathname
req.headersHeader Hash with String keys and values
req.paramsPath, query, and parsed body parameters with Symbol keys
req.bodyParsed JSON value when supported, otherwise the raw body String
req.raw_bodyRaw request body as a Ruby String
req.cookieParsed Cookie header as a Hash with String keys

Parameters

get "/users/:id" do |req, res|
  id = req.params[:id]
  verbose = req.params[:verbose]
  res.return(200, {}, "#{id}: #{verbose}")
end

Path parameters are merged first, followed by query parameters and then supported body parameters. A later source replaces an earlier value with the same key.

JSON bodies

When the content type is exactly application/json and JSON support is enabled by the template, valid JSON is assigned to req.body. Top-level object fields are also merged into req.params.

post "/users" do |req, res|
  data = req.body
  name = data["name"]
  res.return(
    201,
    { "content-type" => "application/json" },
    JSON.generate({ "created" => name })
  )
end

If parsing fails, req.body remains the raw String. Use req.raw_body when the original payload is required regardless of content type.

Form bodies

For an exact application/x-www-form-urlencoded content type, decoded form fields are merged into req.params.

Headers

Header casing and filtering depend on the platform adapter. The Cloudflare adapter currently passes lowercase Workers header names but omits cf-connecting-ip, cf-ray, and names beginning with x-.