global.HeadersInit
What Headers and RequestInit.headers take: a Headers, name-value pairs, or a record of strings.
Utilização
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();Declaração do tipo
type HeadersInit = Headers | [string, string][] | Record<string, string>;Membros 4
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
forEach | string | ((callback: (value: string, name: string, headers: Headers) => void) => void) | ((callbackfn: (value: [string, string], index: number, array: [string, string][]) => void, thisArg?: any) => void) | Sim | Performs the specified action for each element in an array. |
keys | string | (() => string[]) | (() => ArrayIterator<number>) | Sim | Returns an iterable of keys in the array |
values | string | (() => string[]) | (() => ArrayIterator<[string, string]>) | Sim | Returns an iterable of values in the array |
entries | string | (() => [string, string][]) | (() => ArrayIterator<[number, [string, string]]>) | Sim | Returns an iterable of key, value pairs for every entry in the array |
Gerado a partir das declarações TypeScript públicas: assinaturas, props e predefinições vêm da fonte verificada, as descrições da sua JSDoc. Nenhuma predefinição é inventada.