Helia Routing V1 HTTP API
    Preparing search index...

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

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

    import { delegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
    import { CID } from 'multiformats/cid'
    import { defaultLogger } from '@libp2p/logger'

    const client = delegatedRoutingV1HttpApiClient({
    url: 'https://example.org'
    })({
    logger: defaultLogger()
    })

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

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

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

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

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

    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:

    // disable caching
    const client = delegatedRoutingV1HttpApiClient({
    url: 'https://example.org'
    cacheTTL: 0
    })({
    logger: defaultLogger()
    })

    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.

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

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

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

    Interfaces

    DelegatedRoutingV1HttpApiClient
    DelegatedRoutingV1HttpApiClientComponents
    DelegatedRoutingV1HttpApiClientInit
    FilterOptions
    PeerRecord

    Type Aliases

    GetClosestPeersOptions
    GetIPNSOptions
    GetPeersOptions
    GetProvidersOptions

    Functions

    delegatedRoutingV1HttpApiClient
    delegatedRoutingV1HttpApiClientContentRouting
    delegatedRoutingV1HttpApiClientPeerRouting