Utilisation

Accept supported request-header formats.

tsx
// Accept supported request-header formats.
function authorized(token: string, extra: HeadersInit = {}): Headers {
  const headers = new Headers(extra);

  headers.set('Authorization', `Bearer ${token}`);

  return headers;
}

const response = await fetch('https://api.example.com/me', {
  headers: authorized('abc123', [['Accept', 'application/json']]),
});
const me = await response.json();

Déclaration du type

ts
type HeadersInit = Headers | [string, string][] | Record<string, string>;

Membres 4

NomTypeRequisDescription
forEachstring | ((callback: (value: string, name: string, headers: Headers) => void) => void) | ((callbackfn: (value: [string, string], index: number, array: [string, string][]) => void, thisArg?: any) => void)OuiPerforms the specified action for each element in an array.
@param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.@param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
keysstring | (() => string[]) | (() => ArrayIterator<number>)OuiReturns an iterable of keys in the array
valuesstring | (() => string[]) | (() => ArrayIterator<[string, string]>)OuiReturns an iterable of values in the array
entriesstring | (() => [string, string][]) | (() => ArrayIterator<[number, [string, string]]>)OuiReturns an iterable of key, value pairs for every entry in the array
Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.