Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
docs: update examples (#105)
Browse files Browse the repository at this point in the history
Make examples use ESM
  • Loading branch information
achingbrain authored Sep 7, 2021
1 parent 596a342 commit fa9628b
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,31 @@
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.

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

(async () => {
const result = await getResponse(ipfsNode, ipfsPath)
console.log(result)
})()
const result = await getResponse(ipfsNode, ipfsPath)
console.log(result)
```

### Using protocol-agnostic resolver

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:

```js
const { resolver } = require('ipfs-http-response')
import { resolver } from 'ipfs-http-response'

(async () => {
const result = await resolver.cid(ipfsNode, ipfsPath)
console.log(result)
})()
const result = await resolver.cid(ipfsNode, ipfsPath)
console.log(result)
```

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`:


```js
const { resolver } = require('ipfs-http-response')
import { resolver } from 'ipfs-http-response'

(async () => {
const result = await resolver.directory(ipfsNode, ipfsPath, cid)
console.log(result)
})()
const result = await resolver.directory(ipfsNode, ipfsPath, cid)
console.log(result)
```

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

0 comments on commit fa9628b

Please sign in to comment.