handleRequest
Dispatch an HTTP data request to a server route.
Compatibility
Import from @kasperrt/smolter/react/server @kasperrt/smolter/preact/server
Signature
function handleRequest(
routes: readonly Route[],
request: Request,
): Promise<Response>;Parameters
routes is the server route table. request must have the intended route URL, method, headers, body, and signal.
Returns
A Promise<Response>: handler data as JSON, a returned Response, or a JSON error response.
Usage
Import this API from one of the entry points listed above. Keep server and build helpers in their dedicated subpaths.
const response = await handleRequest(serverRoutes, request);
return response;Behavior and edge cases
GET invokes loader. POST, PUT, PATCH, and DELETE invoke action. Missing routes return 404; absent handlers and unsupported methods return 405; errors return 500. Returned Location redirects are translated into X-Smolter-Redirect for the browser transport. This dispatches data, not HTML.