Skip to content
This repository was archived by the owner on Sep 28, 2021. It is now read-only.

Commit fa9628b

Browse files
authored
docs: update examples (#105)
Make examples use ESM
1 parent 596a342 commit fa9628b

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

README.md

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,31 @@
2424
This project creates a HTTP response for an IPFS Path. This response can be a file, a HTML with directory listing or the entry point of a web page.
2525

2626
```js
27-
const { getResponse } = require('ipfs-http-response')
27+
import { getResponse } from 'ipfs-http-response'
2828

29-
(async () => {
30-
const result = await getResponse(ipfsNode, ipfsPath)
31-
console.log(result)
32-
})()
29+
const result = await getResponse(ipfsNode, ipfsPath)
30+
console.log(result)
3331
```
3432

3533
### Using protocol-agnostic resolver
3634

3735
This module also exports the used ipfs `resolver`, which should be used when the response needs to be customized or non-HTTP transport is used:
3836

3937
```js
40-
const { resolver } = require('ipfs-http-response')
38+
import { resolver } from 'ipfs-http-response'
4139

42-
(async () => {
43-
const result = await resolver.cid(ipfsNode, ipfsPath)
44-
console.log(result)
45-
})()
40+
const result = await resolver.cid(ipfsNode, ipfsPath)
41+
console.log(result)
4642
```
4743

4844
If `ipfsPath` points at a directory, `resolver.cid` will throw Error `This dag node is a directory` with a `cid` attribute that can be passed to `resolver.directory`:
4945

5046

5147
```js
52-
const { resolver } = require('ipfs-http-response')
48+
import { resolver } from 'ipfs-http-response'
5349

54-
(async () => {
55-
const result = await resolver.directory(ipfsNode, ipfsPath, cid)
56-
console.log(result)
57-
})()
50+
const result = await resolver.directory(ipfsNode, ipfsPath, cid)
51+
console.log(result)
5852
```
5953

6054
`result` will be either a `string` with HTML directory listing or an array with CIDs of `index` pages present in inspected directory.

0 commit comments

Comments
 (0)