1 |
|
2 |
|
3 |
|
4 | export declare class HttpClientConfiguration {
|
5 | |
6 |
|
7 |
|
8 | baseUrl: string;
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | defaults: RequestInit;
|
16 | |
17 |
|
18 |
|
19 | interceptors: Interceptor[];
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | withBaseUrl(baseUrl: string): HttpClientConfiguration;
|
28 | |
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | withDefaults(defaults: RequestInit): HttpClientConfiguration;
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | withInterceptor(interceptor: Interceptor): HttpClientConfiguration;
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | useStandardConfiguration(): HttpClientConfiguration;
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | rejectErrorResponses(): HttpClientConfiguration;
|
66 | withRetry(config?: RetryConfiguration): HttpClientConfiguration;
|
67 | }
|
68 |
|
69 |
|
70 |
|
71 | export declare class HttpClient {
|
72 | |
73 |
|
74 |
|
75 |
|
76 | activeRequestCount: number;
|
77 | |
78 |
|
79 |
|
80 | isRequesting: boolean;
|
81 | |
82 |
|
83 |
|
84 | isConfigured: boolean;
|
85 | |
86 |
|
87 |
|
88 | baseUrl: string;
|
89 | |
90 |
|
91 |
|
92 | defaults: RequestInit;
|
93 | |
94 |
|
95 |
|
96 | interceptors: Interceptor[];
|
97 | |
98 |
|
99 |
|
100 | constructor();
|
101 | /**
|
102 | * Configure this client with default settings to be used by all requests.
|
103 | *
|
104 | * @param config A configuration object, or a function that takes a config
|
105 | * object and configures it.
|
106 | * @returns The chainable instance of this HttpClient.
|
107 | * @chainable
|
108 | */
|
109 | configure(config: RequestInit | ((config: HttpClientConfiguration) => void) | HttpClientConfiguration): HttpClient;
|
110 | /**
|
111 | * Starts the process of fetching a resource. Default configuration parameters
|
112 | * will be applied to the Request. The constructed Request will be passed to
|
113 | * registered request interceptors before being sent. The Response will be passed
|
114 | * to registered Response interceptors before it is returned.
|
115 | *
|
116 | * See also https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
|
117 | *
|
118 | * @param input The resource that you wish to fetch. Either a
|
119 | * Request object, or a string containing the URL of the resource.
|
120 | * @param init An options object containing settings to be applied to
|
121 | * the Request.
|
122 | * @returns A Promise for the Response from the fetch request.
|
123 | */
|
124 | fetch(input: Request | string, init?: RequestInit): Promise<Response>;
|
125 | buildRequest(input: string | Request, init: RequestInit): Request;
|
126 | /**
|
127 | * Calls fetch as a GET request.
|
128 | *
|
129 | * @param input The resource that you wish to fetch. Either a
|
130 | * Request object, or a string containing the URL of the resource.
|
131 | * @param init An options object containing settings to be applied to
|
132 | * the Request.
|
133 | * @returns A Promise for the Response from the fetch request.
|
134 | */
|
135 | get(input: Request | string, init?: RequestInit): Promise<Response>;
|
136 | /**
|
137 | * Calls fetch with request method set to POST.
|
138 | *
|
139 | * @param input The resource that you wish to fetch. Either a
|
140 | * Request object, or a string containing the URL of the resource.
|
141 | * @param body The body of the request.
|
142 | * @param init An options object containing settings to be applied to
|
143 | * the Request.
|
144 | * @returns A Promise for the Response from the fetch request.
|
145 | */
|
146 | post(input: Request | string, body?: any, init?: RequestInit): Promise<Response>;
|
147 | /**
|
148 | * Calls fetch with request method set to PUT.
|
149 | *
|
150 | * @param input The resource that you wish to fetch. Either a
|
151 | * Request object, or a string containing the URL of the resource.
|
152 | * @param body The body of the request.
|
153 | * @param init An options object containing settings to be applied to
|
154 | * the Request.
|
155 | * @returns A Promise for the Response from the fetch request.
|
156 | */
|
157 | put(input: Request | string, body?: any, init?: RequestInit): Promise<Response>;
|
158 | /**
|
159 | * Calls fetch with request method set to PATCH.
|
160 | *
|
161 | * @param input The resource that you wish to fetch. Either a
|
162 | * Request object, or a string containing the URL of the resource.
|
163 | * @param body The body of the request.
|
164 | * @param init An options object containing settings to be applied to
|
165 | * the Request.
|
166 | * @returns A Promise for the Response from the fetch request.
|
167 | */
|
168 | patch(input: Request | string, body?: any, init?: RequestInit): Promise<Response>;
|
169 | /**
|
170 | * Calls fetch with request method set to DELETE.
|
171 | *
|
172 | * @param input The resource that you wish to fetch. Either a
|
173 | * Request object, or a string containing the URL of the resource.
|
174 | * @param body The body of the request.
|
175 | * @param init An options object containing settings to be applied to
|
176 | * the Request.
|
177 | * @returns A Promise for the Response from the fetch request.
|
178 | */
|
179 | delete(input: Request | string, body?: any, init?: RequestInit): Promise<Response>;
|
180 | }
|
181 | /**
|
182 | * Interceptors can process requests before they are sent, and responses
|
183 | * before they are returned to callers.
|
184 | */
|
185 | export interface Interceptor {
|
186 | |
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | request?: (request: Request) => Request | Response | Promise<Request | Response>;
|
195 | |
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 | requestError?: (error: any) => Request | Response | Promise<Request | Response>;
|
204 | |
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 | response?: (response: Response, request?: Request) => Response | Promise<Response>;
|
212 | |
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 | responseError?: (error: any, request?: Request, httpClient?: HttpClient) => Response | Promise<Response>;
|
222 | }
|
223 | export declare type ValidInterceptorMethodName = keyof Interceptor;
|
224 |
|
225 |
|
226 |
|
227 |
|
228 | export interface RequestInit {
|
229 | |
230 |
|
231 |
|
232 | method?: string;
|
233 | |
234 |
|
235 |
|
236 | headers?: Headers | Object;
|
237 | |
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | body?: Blob | BufferSource | FormData | URLSearchParams | ReadableStream | string | null;
|
244 | |
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 | mode?: string;
|
251 | |
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 | credentials?: string;
|
258 | |
259 |
|
260 |
|
261 | cache?: string;
|
262 | |
263 |
|
264 |
|
265 |
|
266 |
|
267 | redirect?: string;
|
268 | |
269 |
|
270 |
|
271 | referrer?: string;
|
272 | |
273 |
|
274 |
|
275 | integrity?: string;
|
276 | |
277 |
|
278 |
|
279 | signal?: AbortSignal | null;
|
280 | }
|
281 | export interface RetryConfiguration {
|
282 | maxRetries: number;
|
283 | interval?: number;
|
284 | strategy?: number | ((retryCount: number) => number);
|
285 | minRandomInterval?: number;
|
286 | maxRandomInterval?: number;
|
287 | counter?: number;
|
288 | requestClone?: Request;
|
289 | doRetry?: (response: Response, request: Request) => boolean | Promise<boolean>;
|
290 | beforeRetry?: (request: Request, client: HttpClient) => Request | Promise<Request>;
|
291 | }
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 | export declare function json(body: any, replacer?: any): string;
|
300 | export declare const retryStrategy: {
|
301 | fixed: 0;
|
302 | incremental: 1;
|
303 | exponential: 2;
|
304 | random: 3;
|
305 | };
|
306 | export declare class RetryInterceptor implements Interceptor {
|
307 | retryConfig: RetryConfiguration;
|
308 | constructor(retryConfig?: RetryConfiguration);
|
309 | request(request: Request): Request;
|
310 | response(response: Response, request?: Request): Response;
|
311 | responseError(error: Response, request?: Request, httpClient?: HttpClient): Promise<Response>;
|
312 | } |
\ | No newline at end of file |