Package Exports
- ipfs-http-response
- ipfs-http-response/src/utils/content-type
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ipfs-http-response) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
js-ipfs-http-response
Creates an HTTP response from an IPFS Hash
Lead Maintainer
Installation
npm install ipfs-http-response
Usage
Creating HTTP Response
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.
const { getResponse } = require('ipfs-http-response')
(async () => {
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:
const { resolver } = require('ipfs-http-response')
(async () => {
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
:
const { resolver } = require('ipfs-http-response')
(async () => {
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.