Verwendung

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();

Typdeklaration

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

Mitglieder 4

NameTypErforderlichBeschreibung
forEachstring | ((callback: (value: string, name: string, headers: Headers) => void) => void) | ((callbackfn: (value: [string, string], index: number, array: [string, string][]) => void, thisArg?: any) => void)JaPerforms 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>)JaReturns an iterable of keys in the array
valuesstring | (() => string[]) | (() => ArrayIterator<[string, string]>)JaReturns an iterable of values in the array
entriesstring | (() => [string, string][]) | (() => ArrayIterator<[number, [string, string]]>)JaReturns an iterable of key, value pairs for every entry in the array
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.