Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@helia/delegated-routing-v1-http-api-client

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@helia/delegated-routing-v1-http-api-client

A Delegated Routing V1 HTTP API client

  • 4.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Helia logo

@helia/delegated-routing-v1-http-api-client

ipfs.tech Discuss codecov CI

A Delegated Routing V1 HTTP API client

About

A client implementation of the IPFS Delegated Routing V1 HTTP API that can be used to interact with any compliant server implementation.

Example

import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
import { CID } from 'multiformats/cid'

const client = createDelegatedRoutingV1HttpApiClient('https://example.org')

for await (const prov of getProviders(CID.parse('QmFoo'))) {
  // ...
}

How to use with libp2p

The client can be configured as a libp2p service, this will enable it as both a ContentRouting and a PeerRouting implementation

Example

import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
import { createLibp2p } from 'libp2p'
import { peerIdFromString } from '@libp2p/peer-id'

const client = createDelegatedRoutingV1HttpApiClient('https://example.org')
const libp2p = await createLibp2p({
  // other config here
  services: {
    delegatedRouting: client
  }
})

// later this will use the configured HTTP gateway
await libp2p.peerRouting.findPeer(peerIdFromString('QmFoo'))

Caching

By default, the client caches successful (200) delegated routing responses in browser environments (that support the Cache API) for a duration of 5 minutes. The client does this by adding an x-cache-expires header to the response object.

If caching is enabled, the client will cache responses for the duration of cacheTTL milliseconds. If cacheTTL is 0, caching is disabled:

Example

// disable caching
const client = createDelegatedRoutingV1HttpApiClient('https://example.org', { cacheTTL: 0 })

Filtering with IPIP-484

The client can be configured to pass filter options to the delegated routing server as defined in IPIP-484. The filter options be set globally, by passing them to the client constructor, or on a per-request basis.

Example

import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
import { createLibp2p } from 'libp2p'
import { peerIdFromString } from '@libp2p/peer-id'

// globally set filter options
const client = createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev', {
  filterProtocols: ['transport-bitswap', 'unknown', 'transport-ipfs-gateway-http'],
  filterAddrs: ['webtransport', 'webrtc-direct', 'wss']
})

// per-request filter options
for await (const prov of getProviders(CID.parse('bafy'), {
  filterProtocols: ['transport-ipfs-gateway-http'],
  filterAddrs: ['!p2p-circuit']
})) {
  // ...
}

Install

$ npm i @helia/delegated-routing-v1-http-api-client

API Docs

License

Licensed under either of

Contribute

Contributions welcome! Please check out the issues.

Also see our contributing document for more information on how we work, and about contributing in general.

Please be aware that all interactions related to this repo are subject to the IPFS Code of Conduct.

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.

Keywords

FAQs

Package last updated on 19 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc