Skip to content

Commit b56765f

Browse files
committed
Refactor example documentation structure and add CacheableLookup example
1 parent 02c3a67 commit b56765f

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

docs/examples/README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

2-
## undici.request() examples
2+
# undici.request() examples
3+
4+
## A simple GET request, read the response body as text
35

4-
### A simple GET request, read the response body as text:
56
```js
67
const { request } = require('undici')
78
async function getRequest (port = 3001) {
@@ -19,7 +20,8 @@ async function getRequest (port = 3001) {
1920
}
2021
```
2122

22-
### A JSON POST request, read the response body as json:
23+
## A JSON POST request, read the response body as json
24+
2325
```js
2426
const { request } = require('undici')
2527
async function postJSONRequest (port = 3001) {
@@ -44,7 +46,8 @@ async function postJSONRequest (port = 3001) {
4446
}
4547
```
4648

47-
### A Form POST request, read the response body as text:
49+
## A Form POST request, read the response body as text
50+
4851
```js
4952
const { request } = require('undici')
5053
async function postFormRequest (port = 3001) {
@@ -98,7 +101,8 @@ async function formDataBlobRequest () {
98101

99102
```
100103

101-
### A DELETE request
104+
## A DELETE request
105+
102106
```js
103107
const { request } = require('undici')
104108
async function deleteRequest (port = 3001) {
@@ -125,3 +129,18 @@ async function deleteRequest (port = 3001) {
125129
}
126130
}
127131
```
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

Comments
 (0)