Skip to content

Accept

reference
1 min readUpdated

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

PropertyType
typestring
paramsRecord<string, string>
qnumber

Diagram

mermaid
graph LR
  Header[HTTP Accept header] --> Accept[Accept]
  Accept --> Type[type: string]
  Accept --> Params[params: Record&lt;string, string&gt;]
  Accept --> Quality[q: number]

Usage

ts
import 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 type as the parsed media type, such as application/json or text/html.
  • Store media-type parameters in params as string key-value pairs.
  • Use q when 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 Accept header parsing and response content-negotiation code.

Was this page helpful?

Download as PDF
Accept — Hono (narrator proof)