API reference
stackpress/http
stackpress/http is the Node-style HTTP runtime shelf. It exposes the most common server bootstrap helpers, request/response primitives, lifecycle routers, and request parsing helpers for applications running on the Node HTTP model.
Import
import {
server,
router,
action,
gateway,
handler
} from 'stackpress/http';
When To Use It
Use this path when your app is built around the Node HTTP request/response model and you want the most common Stackpress server runtime entrypoint.
Export Inventory
| Export | Kind | Purpose |
|---|---|---|
server | function | Create an HTTP server instance |
router | function | Create an HTTP router |
action | helper namespace/function family | Wrap request handlers into Stackpress actions |
gateway, handler | functions | Adapt handlers into the Stackpress runtime |
Request, Response, Router, Server, Route | runtime types | Core HTTP runtime shapes |
ConfigLoader, PluginLoader | classes | Load config and plugins |
ActionRouter, EntryRouter, ImportRouter, ViewRouter | classes | Resolve lifecycle route tasks |
cookie, session | helpers | Read/write cookie and session state |
objectFromQuery, objectFromFormData, objectFromJson, formDataToObject | helpers | Parse inbound request data |
withUnknownHost | helper | Build a host fallback wrapper |
Status, Exception | classes | Response status and exception helpers |
Detailed Exports
server
- Kind: function
- Signature shape:
server(options?) - Arguments:
options?: HTTP server options- Returns an
HttpServerinstance that can load config, register plugins, and resolve lifecycle listeners such asconfig,listen, androute.
import { server } from 'stackpress/http';
const app = server();
app.config.set({ server: { mode: 'development' } });
await app.bootstrap();
router
- Kind: function
- Signature shape:
router(...) - Use it to create a route-aware HTTP router when you are working below the full server bootstrap level.
- Returns an
HttpRouter.
import { router } from 'stackpress/http';
const routes = router();
action
- Kind: helper namespace/function family
- Common usage:
action(async function Name({ req, res, ctx }: RouteProps) { ... }) - Use it to create Stackpress handlers that receive the framework request context.
- Returns an
HttpAction.
import { action } from 'stackpress/http';
import type { RouteProps } from 'stackpress/types';
export default action(async function HomePage({ res }: RouteProps) {
res.results({ title: 'Hello' });
});
gateway
- Kind: function
- Use it when you need a gateway-style adapter for incoming HTTP requests before they hit your action or route layer.
- Returns a gateway function compatible with the HTTP runtime.
import { gateway } from 'stackpress/http';
handler
- Kind: function
- Use it to adapt raw logic into a Stackpress-compatible route handler.
- Returns a route handler function compatible with the HTTP runtime.
import { handler } from 'stackpress/http';
ConfigLoader and PluginLoader
- Kind: classes
ConfigLoaderloads config modules into the runtime.PluginLoaderloads the plugin list into the runtime.- Returns loader instances used internally by server bootstrap and available for advanced integrations.
import { ConfigLoader, PluginLoader } from 'stackpress/http';
const configs = new ConfigLoader();
const plugins = new PluginLoader();
Request, Response, Router, Server, Route
- Kind: runtime types/classes
- Use them to annotate app code or to understand the core runtime shapes.
Requestcarries parsed request data and request metadata.Responsecarries body, result, status, and data payload state.Routermatches routes to handlers.Servercoordinates config, plugins, and lifecycle resolution.Routerepresents a single registered route entry.
import type { Request, Response } from 'stackpress/http';
function logRequest(req: Request, res: Response) {
console.log(req.method, res.code);
}
Request Parsing Helpers
objectFromQuery
- Kind: function
- Use it to convert a query string or query structure into a plain object.
- Returns a parsed object representation of the query input.
import { objectFromQuery } from 'stackpress/http';
const query = objectFromQuery('page=1&sort=title');
objectFromFormData and formDataToObject
- Kind: functions
- Use them to convert
FormData-shaped input into plain objects. - Returns plain object data that can be pushed into Stackpress request flows.
import { formDataToObject } from 'stackpress/http';
const data = formDataToObject(formData);
objectFromJson
- Kind: function
- Use it to parse JSON input into a plain object.
- Returns a parsed object.
import { objectFromJson } from 'stackpress/http';
const payload = objectFromJson('{"title":"Hello"}');
cookie
- Kind: helper
- Use it to read or write cookie values in HTTP request/response flows.
import { cookie } from 'stackpress/http';
session
- Kind: helper
- Use it to read or write session state from HTTP request/response flows.
import { session } from 'stackpress/http';
withUnknownHost
- Kind: helper
- Use it to provide a safe host fallback when a request does not carry a usable host value.
import { withUnknownHost } from 'stackpress/http';
Integration Example
import { server as http, action } from 'stackpress/http';
import type { RouteProps } from 'stackpress/types';
const app = http();
app.import.get('/', () => import('./pages/home.js'));
export default action(async function HomePage({ res }: RouteProps) {
res.results({ title: 'Hello Stackpress' });
});