request

The request global object contains information about the incoming HTTP request. It is read-only and available in every script.

Properties

PropertyTypeDescription
request.methodstringHTTP method (GET, POST, PUT, DELETE, etc.)
request.uristringFull request URI including query string
request.pathstringPath without query string
request.queryobjectParsed query string parameters
request.headersobjectRequest headers (lowercase keys)
request.bodystringRaw request body
request.cookiesobjectParsed cookies

request.method

The HTTP method as an uppercase string.

if (request.method === "POST") {
    // Handle form submission
}

request.uri

The full URI as requested by the client, including the query string.

// For: /search?q=hello&page=2
request.uri  // "/search?q=hello&page=2"

request.path

The path portion of the URI without the query string.

// For: /search?q=hello
request.path  // "/search"

request.query

An object containing parsed query string parameters. All values are strings.

// For: /page?name=Alice&age=30
request.query.name  // "Alice"
request.query.age   // "30"

request.headers

An object containing the request headers. Keys are lowercase with hyphens.

request.headers["content-type"]  // "application/json"
request.headers["host"]          // "example.com"
request.headers["user-agent"]    // "Mozilla/5.0 ..."

request.body

The raw request body as a string. Typically used with POST and PUT requests.

if (request.method === "POST") {
    const data = JSON.parse(request.body);
    // Process data
}

request.cookies

An object containing cookies sent by the client.

const theme = request.cookies.theme || "light";
const token = request.cookies.auth_token;
Was this page helpful?