1
1
2
- ## undici.request() examples
2
+ # undici.request() examples
3
+
4
+ ## A simple GET request, read the response body as text
3
5
4
- ### A simple GET request, read the response body as text:
5
6
``` js
6
7
const { request } = require (' undici' )
7
8
async function getRequest (port = 3001 ) {
@@ -19,7 +20,8 @@ async function getRequest (port = 3001) {
19
20
}
20
21
```
21
22
22
- ### A JSON POST request, read the response body as json:
23
+ ## A JSON POST request, read the response body as json
24
+
23
25
``` js
24
26
const { request } = require (' undici' )
25
27
async function postJSONRequest (port = 3001 ) {
@@ -44,7 +46,8 @@ async function postJSONRequest (port = 3001) {
44
46
}
45
47
```
46
48
47
- ### A Form POST request, read the response body as text:
49
+ ## A Form POST request, read the response body as text
50
+
48
51
``` js
49
52
const { request } = require (' undici' )
50
53
async function postFormRequest (port = 3001 ) {
@@ -98,7 +101,8 @@ async function formDataBlobRequest () {
98
101
99
102
```
100
103
101
- ### A DELETE request
104
+ ## A DELETE request
105
+
102
106
``` js
103
107
const { request } = require (' undici' )
104
108
async function deleteRequest (port = 3001 ) {
@@ -125,3 +129,18 @@ async function deleteRequest (port = 3001) {
125
129
}
126
130
}
127
131
```
132
+
133
+ # Cacheable DNS Lookup
134
+
135
+ ## Using CacheableLookup to cache DNS lookups in undici
136
+
137
+ ``` js
138
+ import { Agent } from ' undici'
139
+ import CacheableLookup from ' cacheable-lookup' ;
140
+
141
+ const cacheable = new CacheableLookup (opts)
142
+
143
+ const agent = new Agent ({
144
+ connect: { lookup: cacheable .lookup }
145
+ })
146
+ ```
0 commit comments