File tree 7 files changed +60
-4
lines changed
7 files changed +60
-4
lines changed Original file line number Diff line number Diff line change @@ -3,10 +3,37 @@ title: Fetch
3
3
ref : https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch
4
4
---
5
5
6
- ## Basic
6
+ ## Request
7
7
8
- Issue a GET request:
8
+ A [ Request] ( https://developer.mozilla.org/en-US/docs/Web/API/Request/Request )
9
+ is built of an ` input ` (URL) and ` options ` .
10
+
11
+ Make a GET request:
12
+
13
+ ``` js
14
+ fetch (' https://example.com/' ).then (callback);
15
+ ```
16
+
17
+ Make a ` application/json ` POST request:
18
+
19
+ ``` js
20
+ const url = ' https://example.com/' ;
21
+ const options = {
22
+ headers: { ' Content-Type' : ' application/json' },
23
+ method: ' POST' ,
24
+ body: JSON .stringify ({ username: ' example' }),
25
+ };
26
+ fetch (url, options).then (callback);
27
+ ```
28
+
29
+ ## Response
30
+
31
+ A [ Response] ( https://developer.mozilla.org/en-US/docs/Web/API/Response )
32
+ object is returned.
9
33
10
34
``` js
11
- fetch (' https://example.com/' ).then (res => console .log (res .status ));
35
+ fetch (' https://example.com/' ).then ((res ) => {
36
+ console .log (res .status );
37
+ res .text ().then ((text ) => console .log (text));
38
+ });
12
39
```
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Built-in
3
+ ref : https://nodejs.org/api/process.html
4
+ ---
5
+
6
+ ## Process
7
+
8
+ | Variable | Description |
9
+ | ------------- | ----------------------------------------- |
10
+ | ` process.env ` | A object containing the user environment. |
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ Open the interactive console:
16
16
irb
17
17
```
18
18
19
+ ## Variables
20
+
21
+ | Variable | Description |
22
+ | -------- | --------------------------------------- |
23
+ | ` ENV ` | A hash containing the user environment. |
24
+
19
25
## Functions
20
26
21
27
Simple printing:
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ Library to make HTTP requests.
11
11
require ' net/http'
12
12
```
13
13
14
+ ## Request
15
+
14
16
Make a GET request:
15
17
16
18
``` ruby
@@ -25,3 +27,14 @@ url = URI('https://example.com/')
25
27
data = JSON .generate(myhash)
26
28
Net ::HTTP .post(url, data, { ' content-type' : ' application/json' })
27
29
```
30
+
31
+ ## Response
32
+
33
+ A [ Net::HTTPResponse] ( https://docs.ruby-lang.org/en/3.4/Net/HTTPResponse.html )
34
+ object is returned.
35
+
36
+ ``` ruby
37
+ res = Net ::HTTP .post(...)
38
+ puts res.code
39
+ puts res.body
40
+ ```
Original file line number Diff line number Diff line change 1
1
---
2
- title : Built-ins
2
+ title : Built-in
3
3
man : zshbuiltins
4
4
---
5
5
You can’t perform that action at this time.
0 commit comments