global.HeadersInit
What Headers and RequestInit.headers take: a Headers, name-value pairs, or a record of strings.
Usage
Accept supported request-header formats.
// 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();Type declaration
type HeadersInit = Headers | [string, string][] | Record<string, string>;Members 4
| Name | Type | Required | Description |
|---|---|---|---|
forEach | string | ((callback: (value: string, name: string, headers: Headers) => void) => void) | ((callbackfn: (value: [string, string], index: number, array: [string, string][]) => void, thisArg?: any) => void) | Yes | Performs the specified action for each element in an array. |
keys | string | (() => string[]) | (() => ArrayIterator<number>) | Yes | Returns an iterable of keys in the array |
values | string | (() => string[]) | (() => ArrayIterator<[string, string]>) | Yes | Returns an iterable of values in the array |
entries | string | (() => [string, string][]) | (() => ArrayIterator<[number, [string, string]]>) | Yes | Returns an iterable of key, value pairs for every entry in the array |
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.