@stacksjs/router
Version:
The Stacks framework router.
25 lines (24 loc) • 1.24 kB
TypeScript
/*`,
* not `application/json`). This predicate fixes that asymmetry by making
* JSON the default unless the client explicitly opts into HTML.
*/
export declare function isApiRequest(req: Request | { headers: Headers }): boolean;
/**
* "Is this request JSON-shaped?" — the single source of truth used across
* the framework to decide JSON vs HTML for responses (errors, primitives,
* empty results) and to widen request-body parsing to every JSON variant.
*
* The historical bug was scattered ad-hoc checks: `error-handler` looked at
* `Accept`, `formatResult` ignored the request entirely, `parseRequestBody`
* did `contentType.includes('application/json')` so `application/vnd.api+json`
* went unparsed. Centralizing the decision here means a future tweak (e.g.,
* treating an `apiResponse: true` route group as always-JSON) lands in one
* place and every response path picks it up.
*/
/**
* Matches `application/json` plus any RFC-6838 structured-suffix subtype:
* `application/vnd.api+json`, `application/ld+json`, `application/hal+json`,
* `application/problem+json`, etc. Case-insensitive; tolerates a trailing
* `;` (for `;charset=utf-8`) or end-of-string.
*/
export declare const JSON_CONTENT_TYPE: unknown;