StackpressGitHub

API reference

Request

Request normalizes incoming request state across Node HTTP and WHATWG-style runtimes. Handlers use it to read query data, post data, headers, session data, and the original runtime resource.

Import

import { Request } from 'stackpress/server';

Instantiation

const req = new Request({
  url: 'http://localhost:3000/articles?page=1',
  method: 'GET'
});

This example creates a request object manually. In normal route handling, the adapter creates req and passes it into the handler props.

Properties

PropertyTypeDescription
dataCallableNestCombined query, post, and extra data.
queryCallableNestURL query parameters.
postCallableNestParsed request body data.
headers`CallableMap<string, string \string[]>`Request headers.
sessionCallableSessionCookie-derived session data.
urlURLNormalized request URL.
methodMethodHTTP method.
body`Body \null`Raw loaded body.
loadedbooleanWhether body loading has completed.
mimetypestringRequest body MIME type.
resourceROriginal runtime request resource.

Methods

load()

Loads and parses the request body with the configured loader.

Returns the request instance for chaining.

await req.load();
const input = req.post.get();

Adapters usually call load() before route handling begins. Call it manually only when you created a request yourself or are testing request parsing.

Data Access Example

const page = req.query.get('page');
const title = req.post.get('title');
const all = req.data();
const userId = req.session.get('userId');

This example shows the common request surfaces. Use req.session to read incoming session data and res.session to write session changes back.