Requires Scripting PRO
The HttpRequest class represents an HTTP request received by the server.
It encapsulates all request information, including path, method, headers, body, client address, and parsed parameters.
An instance of this class is provided as an argument to handler functions registered through HttpServer.registerHandler().
HttpRequest is typically used inside HTTP route handlers to:
application/x-www-form-urlencoded or multipart/form-data)path: stringThe request path (excluding query parameters).
Example:
method: stringThe HTTP method of the request (e.g., "GET", "POST", "PUT", "DELETE").
Example:
headers: Record<string, string>An object containing all HTTP request headers as key–value pairs.
Example:
body: DataThe request body as a Data object.
You can convert it to a string using methods such as toRawString("utf-8").
Example:
address: string | nullThe IP address of the client that made the request.
If the address cannot be determined, this value is null.
Example:
params: Record<string, string>An object containing route parameters defined in the registered path.
Example:
If the request path is /user/123, the response will be:
queryParams: Array<{ key: string; value: string }>An array of query parameter key–value pairs extracted from the request URL.
Example:
hasTokenForHeader(headerName: string, token: string): booleanChecks whether the specified header contains the given token value.
Commonly used for authentication headers such as Authorization.
Parameters:
| Name | Type | Description |
|---|---|---|
headerName |
string |
The name of the header to check (case-insensitive). |
token |
string |
The token string to match. |
Returns:
true if the header contains the tokenfalse otherwiseExample:
parseUrlencodedForm(): Array<{ key: string; value: string }>Parses the request body as application/x-www-form-urlencoded form data.
Typically used for HTML form submissions via POST.
Returns: An array of key–value pairs representing form fields.
Example:
If the body is:
then the output is:
parseMultiPartFormData(): Array<{ name: string | null; filename: string | null; headers: Record<string, string>; data: Data }>Parses multipart/form-data requests, typically used for file uploads.
Returns: An array of form parts, where each element contains:
| Property | Type | Description |
|---|---|---|
name |
string | null |
The field name. |
filename |
string | null |
The uploaded filename if the part is a file, otherwise null. |
headers |
Record<string, string> |
The part’s headers. |
data |
Data |
The raw content of the field or file. |
Example:
The example below shows how to read request data and respond accordingly: