Skip to main content

@std/http@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
function accepts
accepts(request: Request): string[]

Returns an array of media types accepted by the request, in order of preference. If there are no media types supplied in the request, then any media type selector will be returned.

Examples

Example 1

import { accepts } from "@std/http/negotiation";

const req = new Request("https://example.com/", {
  headers: {
    "accept":
      "text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, *\/*;q=0.8",
  },
});

console.log(accepts(req));
// [
//   "text/html",
//   "application/xhtml+xml",
//   "image/webp",
//   "application/xml",
//   "*\/*",
// ]

Parameters

Return Type

accepts(
request: Request,
...types: string[]
): string | undefined

For a given set of media types, return the best match accepted in the request. If no media type matches, then the function returns undefined.

Examples

Example 1

import { accepts } from "@std/http/negotiation";

const req = new Request("https://example.com/", {
  headers: {
    "accept":
      "text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, *\/*;q=0.8",
  },
});

accepts(req, "text/html", "image/webp"); // "text/html";

Parameters

...types: string[]

Return Type

string | undefined

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/http

Import symbol

import { accepts } from "@std/http/negotiation";
or

Import directly with a jsr specifier

import { accepts } from "jsr:@std/http/negotiation";