Skip to content

Accept

reference
1 min readUpdated

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

PropertyType
typestring
paramsRecord<string, string>
qnumber

Diagram

mermaid
graph LR
  Header[Accept header entry] --> Accept[Accept]
  Accept --> Type[type: string]
  Accept --> Params[params: Record<string, string>]
  Accept --> Quality[q: number]

Usage

ts
import 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 type as the parsed media type, such as application/json.
  • Store media-type parameters in params as string values.
  • Preserve the parsed quality value in q for preference comparisons.
  • Handle missing or invalid quality values in the parsing layer before constructing an Accept object.

Relationships

  • IMPORTS → parseAccept

Was this page helpful?

Download as PDF
Accept — Hono (narrator proof)