在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ipfs-shipyard/js-ipfs-http-client-lite开源软件地址:https://github.com/ipfs-shipyard/js-ipfs-http-client-lite开源编程语言:JavaScript 100.0%开源软件介绍:A lightweight JavaScript HTTP client library for IPFS.
Lead MaintainerTable of ContentsInstallThis module requires Node.js and npm to install: npm 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. UsageRunning the daemon with the right portTo interact with the API, you need to have a local daemon running. It needs to be open on the right port. # Show the ipfs config API port to check it is correct
> ipfs config Addresses.API
/ip4/127.0.0.1/tcp/5001
# Set it if it does not match the above output
> ipfs config Addresses.API /ip4/127.0.0.1/tcp/5001
# Restart the daemon after changing the config
# Run the daemon
> ipfs daemon CORSIn 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: $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://example.com"]'
$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST", "GET"]' Custom HTTP HeadersIf 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: const ipfs = IpfsHttpClientLite({
apiUrl: 'http://localhost:5001',
headers: {
Authorization: 'Bearer ' + TOKEN
}
}) Importingconst IpfsHttpClientLite = require('ipfs-http-client-lite')
// Connect to ipfs daemon HTTP API server
const ipfs = IpfsHttpClientLite('http://localhost:5001')
// Note: leaving out the argument will default to this value For ultra small bundle size, import just the methods you need. e.g. const cat = require('ipfs-http-client-lite/src/cat')('http://localhost:5001')
const data = await cat('QmQeEyDPA47GqnduyVVWNdnj6UBPXYPVWogAQoqmAcLx6y') In a web browserBundling 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: <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:
Example: <script src="https://unpkg.com/[email protected]/dist/index.js"
integrity="sha384-5bXRcW9kyxxnSMbOoHzraqa7Z0PQWIao+cgeg327zit1hz5LZCEbIMx/LWKPReuB"
crossorigin="anonymous"></script> The CDN-based IPFS HTTP API provides the const ipfs = window.IpfsHttpClientLite('http://localhost:5001') If you omit the URL, the client will parse const ipfs = window.IpfsHttpClientLite() APIThis module is in heavy development, not all API methods are available (or documented) yet!
Note: All API methods are documented using Promises/async/await but they also accept a callback as their last parameter. TestingWe run tests by executing ContributeFeel free to dive in! Open an issue or submit PRs. Want to hack on IPFS? LicenseDual-licensed under Apache 2.0 and MIT terms:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论