UNPKG

3.02 kBTypeScriptView Raw
1import { Agent as HttpAgent } from 'http';
2import { Agent as HttpsAgent } from 'https';
3
4export declare function fetch(
5 input: RequestInfo,
6 init?: RequestInit,
7): Promise<Response>;
8
9export type RequestAgent = HttpAgent | HttpsAgent;
10
11export type RequestInfo = Request | string;
12
13export declare class Headers implements Iterable<[string, string]> {
14 constructor(init?: HeadersInit);
15
16 append(name: string, value: string): void;
17 delete(name: string): void;
18 get(name: string): string | null;
19 has(name: string): boolean;
20 set(name: string, value: string): void;
21
22 entries(): Iterator<[string, string]>;
23 keys(): Iterator<string>;
24 values(): Iterator<string>;
25 [Symbol.iterator](): Iterator<[string, string]>;
26}
27
28export type HeadersInit = Headers | string[][] | { [name: string]: string };
29
30export declare class Body {
31 readonly bodyUsed: boolean;
32 arrayBuffer(): Promise<ArrayBuffer>;
33 json(): Promise<any>;
34 text(): Promise<string>;
35}
36
37export declare class Request extends Body {
38 constructor(input: Request | string, init?: RequestInit);
39
40 readonly method: string;
41 readonly url: string;
42 readonly headers: Headers;
43
44 clone(): Request;
45}
46
47export interface RequestInit {
48 method?: string;
49 headers?: HeadersInit;
50 body?: BodyInit;
51 mode?: RequestMode;
52 credentials?: RequestCredentials;
53 cache?: RequestCache;
54 redirect?: RequestRedirect;
55 referrer?: string;
56 referrerPolicy?: ReferrerPolicy;
57 integrity?: string;
58
59 // The following properties are node-fetch extensions
60 follow?: number;
61 timeout?: number;
62 compress?: boolean;
63 size?: number;
64 agent?: RequestAgent | false;
65
66 // Cloudflare Workers accept a `cf` property to control Cloudflare features
67 // See https://developers.cloudflare.com/workers/reference/cloudflare-features/
68 cf?: {
69 [key: string]: any;
70 };
71}
72
73export type RequestMode = 'navigate' | 'same-origin' | 'no-cors' | 'cors';
74
75export type RequestCredentials = 'omit' | 'same-origin' | 'include';
76
77export type RequestCache =
78 | 'default'
79 | 'no-store'
80 | 'reload'
81 | 'no-cache'
82 | 'force-cache'
83 | 'only-if-cached';
84
85export type RequestRedirect = 'follow' | 'error' | 'manual';
86
87export type ReferrerPolicy =
88 | ''
89 | 'no-referrer'
90 | 'no-referrer-when-downgrade'
91 | 'same-origin'
92 | 'origin'
93 | 'strict-origin'
94 | 'origin-when-cross-origin'
95 | 'strict-origin-when-cross-origin'
96 | 'unsafe-url';
97
98export declare class Response extends Body {
99 constructor(body?: BodyInit, init?: ResponseInit);
100 static error(): Response;
101 static redirect(url: string, status?: number): Response;
102
103 readonly url: string;
104 readonly redirected: boolean;
105 readonly status: number;
106 readonly ok: boolean;
107 readonly statusText: string;
108 readonly headers: Headers;
109
110 clone(): Response;
111}
112
113export interface ResponseInit {
114 headers?: HeadersInit;
115 status?: number;
116 statusText?: string;
117 // Although this isn't part of the spec, `node-fetch` accepts a `url` property
118 url?: string;
119}
120
121export type BodyInit = ArrayBuffer | ArrayBufferView | string;