Kind: Interface
Source: src/utils/accept.ts
Part of: Utils
Accept represents a parsed media type from an HTTP Accept header. It stores the media type, associated parameters, and the q quality value used when selecting a preferred response format.
Properties
| Property | Type |
|---|---|
type | string |
params | Record<string, string> |
q | number |
Diagram
mermaidgraph LR Header[HTTP Accept header] --> Accept[Accept] Accept --> Type[type: string] Accept --> Params[params: Record<string, string>] Accept --> Quality[q: number]
Usage
tsimport type { Accept } from "./utils/accept";
const acceptedType: Accept = {
type: "application/json",
params: {
charset: "utf-8",
},
q: 1,
};
if (acceptedType.type === "application/json" && acceptedType.q > 0) {
console.log("Return a JSON response");
}
AI Coding Instructions
- Treat
typeas the parsed media type, such asapplication/jsonortext/html. - Store media-type parameters in
paramsas string key-value pairs. - Use
qwhen comparing acceptable response formats; higher values indicate higher preference. - Preserve parsed parameter values as strings rather than coercing them to other types.
- Keep this interface aligned with the
Acceptheader parsing and response content-negotiation code.
Was this page helpful?