Kind: Interface
Source: src/helper/accepts/accepts.ts
Part of: Helper
Accept represents a parsed accepted media type, including its type string, media parameters, and quality value. It can be used by content negotiation helpers when comparing client preferences against available response formats.
Properties
| Property | Type |
|---|---|
type | string |
params | Record<string, string> |
q | number |
Diagram
mermaidgraph LR Header[Accept header entry] --> Accept[Accept] Accept --> Type[type: string] Accept --> Params[params: Record<string, string>] Accept --> Quality[q: number]
Usage
tsimport type { Accept } from "./helper/accepts/accepts";
const requestedQuality = "0.9";
const acceptedType: Accept = {
type: "application/json",
params: {
charset: "utf-8",
},
q: Number.parseFloat(requestedQuality),
};
if (acceptedType.type === "application/json") {
console.log(`Serving ${acceptedType.type}`);
}
AI Coding Instructions
- Keep
typeas the parsed media type, such asapplication/json. - Store media-type parameters in
paramsas string values. - Preserve the parsed quality value in
qfor preference comparisons. - Handle missing or invalid quality values in the parsing layer before constructing an
Acceptobject.
Relationships
- IMPORTS →
parseAccept
Was this page helpful?