-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
40 lines (40 loc) · 1.24 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import * as _ from "./_index.d";
declare global{
var echo: typeof _.echo;
var $: typeof _.$ & string[];
var pipe: typeof _.pipe;
var s: typeof _.s;
/**
* A wrapper around the [node-fetch](https://www.npmjs.com/package/node-fetch) package.
*
* ```js
* // BASIC
* const response1= await fetch('https://medv.io');
* // PROMISE CHAINING
* const text1= await fetch('https://github.com/').then(r=> r.text());
* // AWAITING
* const response2= await fetch('https://api.github.com/users/github');
* const json1= await response.json();
* // POST METHOD
* const json2= await fetch('https://httpbin.org/post', { method: 'POST', body: 'a=1' }).then(r=> r.json());
* // POST METHOD WITH JSON
* const response3= await fetch('https://httpbin.org/post', {
* method: 'post',
* body: JSON.stringify({ a: 1 }),
* headers: {'Content-Type': 'application/json'}
* });
* // ERRORS
* fetch('https://domain.invalid/').catch(echo);
* try{
* await fetch('https://domain.invalid');
* } catch(error){
* echo(error);
* }
* ```
*
* @param url The URL to fetch.
* @param init Request parameters.
* @category Public
*/
function fetch(url: string | _.__fetch.Request, init?: _.__fetch.RequestInit): Promise<_.__fetch.Response>;
}