restipfs

Source restipfs

The restipfs is a local copy of browser ipfs including some small adjustments, to handle a lightweight rest based ipfs connection. It is used to initial files (before bcc and browserified ipfs-js loaded) and small DBCP descriptions.


setProvider

ipfs.setProvider(opts);

set localProvider configuration

Parameters

  1. opts - object: e.g. {host: ‘localhost’, port: ‘5001’}

api_url

ipfs.api_url(path);

build the api connection url

Parameters

  1. path - string: path to build the api url for

Returns

`string: full api enchanced path

Example

restIpfs.api_url(`/ipfs/Qmb...`) => http://localhost:5001/api/v0/ipfs/Qmb

add

ipfs.add(input, callback);

Adds a file to the ipfs

Parameters

  1. input - string: string input of the file
  2. callback - Function: callback called when finished adding

Example

ipfs.add('hello world, wohooo', () => console.log('Finished'))

catText

ipfs.catText(ipfsHash, callback);

Returns a string that is loaded from a ipfs hash

Parameters

  1. ipfsHash - string: ipfs hash to load
  2. callback - Function: callback called when finished loading

Returns

string: result of the ipfs hash

Example

ipfs.catText('Qmb...', (result) => console.log(result))  //==> hello world, wohooo

addJson

ipfs.addJson(jsonObject, callback);

Serializes a json object and saves it using ipfs.add

Parameters

  1. jsonObject - object: json object to save
  2. callback - Function: callback that is called when finished request

Example

ipfs.add({ text: "hello world, wohooo" }, () => console.log('Finished'))

catJson

ipfs.catJson(ipfsHash, callback);

Load data from an ipfs hash and tries an JSON.parse on the result

Parameters

  1. ipfsHash - string: ipfs hash to load
  2. callback - Function: callback called when finished loading

Returns

object: resolved when done

Example

ipfs.catJson('Qmb...', (result) => console.log(result)) // ==> { text: "hello world, wohooo" }