![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main&style=flat-square)
Implementation of the Fetch Protocol
About
An implementation of the Fetch protocol as described here: https://github.com/libp2p/specs/tree/master/fetch
The fetch protocol is a simple protocol for requesting a value corresponding to a key from a peer.
Example
import { createLibp2p } from 'libp2p'
import { fetch } from '@libp2p/fetch'
const libp2p = await createLibp2p({
services: {
fetch: fetch()
}
})
async function my_subsystem_key_lookup(key) {
}
libp2p.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup)
const key = '/my_subsystem_key_prefix/{...}'
const peerDst = PeerId.parse('Qmfoo...')
const value = await libp2p.fetch(peerDst, key)
Install
$ npm i @libp2p/fetch
Browser <script>
tag
Loading this module through a script tag will make it's exports available as Libp2pFetch
in the global namespace.
<script src="https://unpkg.com/@libp2p/fetch/dist/index.min.js"></script>
API Docs
License
Licensed under either of
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.