Skip to content

A multiplexer library, built on top of js-ipfs-http-client.

Notifications You must be signed in to change notification settings

inakineitor/ipfs-multiplexer

Repository files navigation

IPFS Multiplexer Library

A multiplexer library, built on top of js-ipfs-http-client and implementing the interface-ipfs-core.

Lead Maintainer

Iñaki Arango.

Table of Contents

Install

This module uses node.js, and can be installed through npm:

npm install --save ipfs-multiplexer

We support both the Current and Active LTS versions of Node.js. Please see nodejs.org for what these currently are.

Importing the module and usage

import IpfsMultiplexer from 'ipfs-multiplexer';

const ipfsMultiplexer = new IpfsMultiplexer();

// Optionally, you can add your own nodes to the list of available nodes
ipfsMultiplexer.addGateway({
  host: 'localhost',
  port: 5001,
  protocol: 'http',
});

ipfsMultiplexer.get('Qmaisz6NMhDB51cCvNWa1GMS7LU1pAxdF4Ld6Ft9kZEP2a')
  .then(console.log)
  .catch(console.error);

Importing helper functions

import { testGateway } from 'ipfs-multiplexer';

testGateway({
    host: 'localhost',
    port: 5001,
    protocol: 'http',  
  })
  .then(() => {
    // Everything went fine
    console.log('The gateway is up');
  })
  .catch(err => {
    // The error thrown by the gateway during test request
    console.error(err);
  });

In a web browser

through Browserify

Same as in Node.js, you just have to browserify the code before serving it. See the browserify repo for how to do that.

See the example provided by js-ipfs-http-client in the examples folder to get a boilerplate.

through webpack

See the example provided by js-ipfs-http-client in the examples folder to get an idea on how to use a package with webpack.

Custom Headers

If you wish to send custom headers with each request made by this library, for example, the Authorization header. You can use the config to do so:

ipfsMultiplexer.addGateway({
  host: 'localhost',
  port: 5001,
  protocol: 'http',
  headers: {
    authorization: 'Bearer ' + TOKEN,
  },
});

Usage

API

IPFS Core API Compatible

js-ipfs-http-client follows the spec defined by interface-ipfs-core, which concerns the interface to expect from IPFS implementations. This interface is a currently active endeavor. You can use it today to consult the methods available.

IMPORTANTE NOTE: Due to the nature of a multiplexer, the commands from the Network and Node Management categories are not available. Please refere to these links to see which part of the API is not available.

Files

Graph

Additional Options

All core API methods take additional options specific to the HTTP API:

  • headers - An object or Headers instance that can be used to set custom HTTP headers. Note that this option can also be configured globally via the constructor options.
  • timeout - A number or string specifying a timeout for the request. If the timeout is reached before data is received a TimeoutError is thrown. If a number is specified it is interpreted as milliseconds, if a string is passed, it is intepreted according to parse-duration. Note that this option can also be configured globally via the constructor options.
  • searchParams - An object or URLSearchParams instance that can be used to add additional query parameters to the query string sent with each request.

NOTE: The signal property thas is described here is not available with this package, because it is used to abort the requests that have not arrived by the time where the multiplexer already has a valid response.

Development

Testing

We run tests by executing npm test in a terminal window. This will run Node.js test.

NOTE: While because the package conforms with the interface-ipfs-core spec because it extends js-ipfs-http-client, the tests provided by the interface module are yet to be added to this package's tests.

Contribute

ipfs-multiplexer is a work in progress. As such, there's a few things you can do right now to help out:

  • Check out the existing issues!
  • Perform code reviews. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
  • Add tests. There can never be enough tests. Note that interface tests exist inside interface-ipfs-core.
  • Contribute to the js-ipfs-http-client repository by checking out issues, performing code reviews, adding tests or by contributing to their FAQ repository. Remember ipfs-multiplexer is based on js-ipfs-http-client, so every improvement it gets, helps make this package better.

Historical context

This module started as part of docsit-client when we tried to speed up the IPFS operations of our documents, but we realized that it had so much more potential as an independent package.

About

A multiplexer library, built on top of js-ipfs-http-client.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published