Installations
npm install @dorgjelli-test/ipfs-http-client-lite
Developer Guide
Typescript
No
Module System
CommonJS, UMD
Min. Node Version
>=10.0.0
Node Version
14.16.0
NPM Version
6.14.11
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
ipfs-shipyard
Download Statistics
Total Downloads
21,667
Last Day
1
Last Week
5
Last Month
25
Last Year
309
GitHub Statistics
34 Stars
26 Commits
7 Forks
12 Watching
1 Branches
20 Contributors
Bundle Size
18.60 kB
Minified
5.46 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.3.1
Package Id
@dorgjelli-test/ipfs-http-client-lite@0.3.1
Unpacked Size
538.92 kB
Size
127.64 kB
File Count
47
NPM Version
6.14.11
Node Version
14.16.0
Total Downloads
Cumulative downloads
Total Downloads
21,667
Last day
0%
1
Compared to previous day
Last week
-50%
5
Compared to previous week
Last month
66.7%
25
Compared to previous month
Last year
-57.9%
309
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
10
A lightweight JavaScript HTTP client library for IPFS.
An alternative client library for the IPFS HTTP API, aiming to be as lightweight as possible (<20KB) in the browser.
Lead Maintainer
Table of Contents
Install
This module requires Node.js and npm to install:
1npm install --save ipfs-http-client-lite
We support both the Current and Active LTS versions of Node.js. Please see nodejs.org for what these currently are.
Usage
Running the daemon with the right port
To interact with the API, you need to have a local daemon running. It needs to be open on the right port. 5001
is the default, and is used in the examples below, but it can be set to whatever you need.
1# Show the ipfs config API port to check it is correct 2> ipfs config Addresses.API 3/ip4/127.0.0.1/tcp/5001 4# Set it if it does not match the above output 5> ipfs config Addresses.API /ip4/127.0.0.1/tcp/5001 6# Restart the daemon after changing the config 7 8# Run the daemon 9> ipfs daemon
CORS
In a web browser IPFS HTTP client (either browserified or CDN-based) might encounter an error saying that the origin is not allowed. This would be a CORS ("Cross Origin Resource Sharing") failure: IPFS servers are designed to reject requests from unknown domains by default. You can whitelist the domain that you are calling from by changing your ipfs config like this:
1$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://example.com"]' 2$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST", "GET"]'
Custom HTTP 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:
1const ipfs = IpfsHttpClientLite({ 2 apiUrl: 'http://localhost:5001', 3 headers: { 4 Authorization: 'Bearer ' + TOKEN 5 } 6})
Importing
1const IpfsHttpClientLite = require('ipfs-http-client-lite') 2 3// Connect to ipfs daemon HTTP API server 4const ipfs = IpfsHttpClientLite('http://localhost:5001') 5// Note: leaving out the argument will default to this value
For ultra small bundle size, import just the methods you need. e.g.
1const cat = require('ipfs-http-client-lite/src/cat')('http://localhost:5001') 2const data = await cat('QmQeEyDPA47GqnduyVVWNdnj6UBPXYPVWogAQoqmAcLx6y')
In a web browser
Bundling
This module can be bundled with webpack and browserify and should be compatible with most other bundlers.
CDN
Instead of a local installation (and bundling) you may request a remote copy of the IPFS HTTP API client from unpkg CDN.
To always request the latest version, use the following:
1<script src="https://unpkg.com/ipfs-http-client-lite/dist/index.min.js"></script>
You can also use the un-minified version, just remove ".min" from the URL.
For maximum security you may also decide to:
- Reference a specific version of the IPFS HTTP API client (to prevent unexpected breaking changes when a newer latest version is published)
- Generate a SRI hash of that version and use it to ensure integrity
- Set the CORS settings attribute to make anonymous requests to CDN
Example:
1<script src="https://unpkg.com/ipfs-http-client-lite@1.0.0/dist/index.js" 2integrity="sha384-5bXRcW9kyxxnSMbOoHzraqa7Z0PQWIao+cgeg327zit1hz5LZCEbIMx/LWKPReuB" 3crossorigin="anonymous"></script>
The CDN-based IPFS HTTP API provides the IpfsHttpClientLite
constructor as a property of the global window
object. Example:
1const ipfs = window.IpfsHttpClientLite('http://localhost:5001')
If you omit the URL, the client will parse window.location.host
, and use this information. This also works, and can be useful if you want to write apps that can be run from multiple different gateways:
1const ipfs = window.IpfsHttpClientLite()
API
This module is in heavy development, not all API methods are available (or documented) yet!
- IpfsHttpClientLite
- add
- addFromFs
- addFromStream TODO: add docs
- addFromURL TODO: add docs
- addPullStream
- bitswap.stat TODO: add docs
- bitswap.wantlist TODO: add docs
- block.get
- block.put
- block.stat
- bootstrap.add
- bootstrap.list
- bootstrap.rm
- cat
- catPullStream TODO: add docs
- config.get
- config.replace
- config.set
- dag.get
- dag.put
- dag.tree
- dht.findPeer
- dht.findProvs
- dht.get
- dht.provide
- dht.put
- dht.query
- dns
- files.cp
- files.flush
- files.ls
- files.lsPullStream
- files.mkdir
- files.mv
- files.read
- files.readPullStream
- files.rm
- files.stat
- files.write
- id TODO: add docs
- key.export
- key.gen
- key.import
- key.list
- key.rename
- key.rm
- ls TODO: add docs
- lsPullStream TODO: add docs
- name.pubsub.cancel
- name.pubsub.state
- name.pubsub.subs
- object.data
- object.get
- object.links
- object.new
- object.patch.addLink
- object.patch.appendData
- object.patch.rmLink
- object.patch.setData
- object.put
- pin.add
- pin.ls
- pin.rm
- ping TODO: add docs
- pingPullStream TODO: add docs
- pubsub.ls
- pubsub.peers
- pubsub.publish
- pubsub.subscribe
- pubsub.unsubscribe
- refs
- refsPullStream
- refs.local
- refs.localPullStream
- repo.gc
- repo.stat
- repo.version
- resolve
- shutdown
- stats.bitswap
- stats.bw
- stats.bwPullStream
- stats.repo
- swarm.addrs
- swarm.connect
- swarm.disconnect
- swarm.localAddrs
- swarm.peers
- version TODO: add docs
Note: All API methods are documented using Promises/async/await but they also accept a callback as their last parameter.
Testing
We run tests by executing npm test
in a terminal window. This will run both Node.js and Browser tests, both in Chrome and PhantomJS. To ensure that the module conforms with the interface-ipfs-core
spec, we run the batch of tests provided by the interface module, which can be found here.
Contribute
Feel free to dive in! Open an issue or submit PRs.
Want to hack on IPFS?
License
Dual-licensed under Apache 2.0 and MIT terms:
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE-APACHE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
Found 1/24 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 5 are checked with a SAST tool
Score
3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More