Skip to content

Implementation of WHATWG Fetch with support for multiaddrs and libp2p streams.

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

libp2p/js-libp2p-http-fetch

Folders and files

NameName
Last commit message
Last commit date
Oct 29, 2024
Dec 2, 2024
Nov 1, 2024
Nov 1, 2024
Jun 11, 2024
Nov 1, 2024
Apr 18, 2024
Apr 18, 2024
Apr 18, 2024
Oct 29, 2024
Nov 1, 2024
Apr 18, 2024
Oct 29, 2024

Repository files navigation

@libp2p/http-fetch

libp2p.io Discuss codecov CI

Implementation of the WHATWG Fetch API on libp2p streams

About

http implements the WHATWG Fetch api. It can be used as a drop in replacement for the browser's fetch function. It supports http, https, and multiaddr URIs. Use HTTP in p2p networks.

Example

See the examples/ for full examples of how to use the HTTP service.

import { createLibp2p } from 'libp2p'
import { http } from '@libp2p/http-fetch'

const node = await createLibp2p({
    // other options ...
    services: {
      http: http()
    }
})

await node.start()

// Make an http request to a libp2p peer
let resp = await node.services.http.fetch('multiaddr:/dns4/localhost/tcp/1234')
// Or a traditional HTTP request
resp = await node.services.http.fetch('multiaddr:/dns4/example.com/tcp/443/tls/http')
// And of course, you can use the fetch API as you normally would
resp = await node.services.http.fetch('https://example.com')

// This gives you the accessibility of the fetch API with the flexibility of using a p2p network.

Install

$ npm i @libp2p/http-fetch

Browser <script> tag

Loading this module through a script tag will make its exports available as Libp2pHttpFetch in the global namespace.

<script src="https://unpkg.com/@libp2p/http-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.

About

Implementation of WHATWG Fetch with support for multiaddrs and libp2p streams.

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published