39
39
- [ Install] ( #install )
40
40
- [ Next Steps] ( #next-steps )
41
41
- [ Usage] ( #usage )
42
- - [ ` ipfsHttpClient ([options])` ] ( #ipfshttpclientoptions )
42
+ - [ ` create ([options])` ] ( #createoptions )
43
43
- [ Parameters] ( #parameters )
44
44
- [ Options] ( #options )
45
45
- [ Returns] ( #returns )
@@ -92,7 +92,7 @@ Both the Current and Active LTS versions of Node.js are supported. Please see [n
92
92
93
93
## Usage
94
94
95
- #### ` ipfsHttpClient ([options])`
95
+ #### ` create ([options])`
96
96
97
97
> create an instance of the HTTP API client
98
98
@@ -124,16 +124,16 @@ Alternatively it can be an object which may have the following keys:
124
124
#### Example
125
125
126
126
``` JavaScript
127
- const createClient = require (' ipfs-http-client' )
127
+ const { create } = require (' ipfs-http-client' )
128
128
129
129
// connect to the default API address http://localhost:5001
130
- const client = createClient ()
130
+ const client = create ()
131
131
132
132
// connect to a different API
133
- const client = createClient (' http://127.0.0.1:5002' )
133
+ const client = create (' http://127.0.0.1:5002' )
134
134
135
135
// connect using a URL
136
- const client = createClient (new URL (' http://127.0.0.1:5002' ))
136
+ const client = create (new URL (' http://127.0.0.1:5002' ))
137
137
138
138
// call Core API methods
139
139
const { cid } = await client .add (' Hello world!' )
@@ -195,9 +195,8 @@ Returns an async iterable that yields `{ path, content }` objects suitable for p
195
195
##### Example
196
196
197
197
``` js
198
- const IpfsHttpClient = require (' ipfs-http-client' )
199
- const { globSource } = IpfsHttpClient
200
- const ipfs = IpfsHttpClient ()
198
+ const { create , globSource } = require (' ipfs-http-client' )
199
+ const ipfs = create ()
201
200
202
201
const file = await ipfs .add (globSource (' ./docs' , { recursive: true }))
203
202
console .log (file)
@@ -230,9 +229,8 @@ Returns an async iterable that yields `{ path, content }` objects suitable for p
230
229
##### Example
231
230
232
231
``` js
233
- const IpfsHttpClient = require (' ipfs-http-client' )
234
- const { urlSource } = IpfsHttpClient
235
- const ipfs = IpfsHttpClient ()
232
+ const { create , urlSource } = require (' ipfs-http-client' )
233
+ const ipfs = create ()
236
234
237
235
const file = await ipfs .add (urlSource (' https://ipfs.io/images/ipfs-logo.svg' ))
238
236
console .log (file)
@@ -265,19 +263,19 @@ To interact with the API, you need to have a local daemon running. It needs to b
265
263
### Importing the module and usage
266
264
267
265
``` javascript
268
- const ipfsClient = require (' ipfs-http-client' )
266
+ const { create } = require (' ipfs-http-client' )
269
267
270
268
// connect to ipfs daemon API server
271
- const ipfs = ipfsClient (' http://localhost:5001' ) // (the default in Node.js)
269
+ const ipfs = create (' http://localhost:5001' ) // (the default in Node.js)
272
270
273
271
// or connect with multiaddr
274
- const ipfs = ipfsClient (' /ip4/127.0.0.1/tcp/5001' )
272
+ const ipfs = create (' /ip4/127.0.0.1/tcp/5001' )
275
273
276
274
// or using options
277
- const ipfs = ipfsClient ({ host: ' localhost' , port: ' 5001' , protocol: ' http' })
275
+ const ipfs = create ({ host: ' localhost' , port: ' 5001' , protocol: ' http' })
278
276
279
277
// or specifying a specific API path
280
- const ipfs = ipfsClient ({ host: ' 1.1.1.1' , port: ' 80' , apiPath: ' /ipfs/api/v0' })
278
+ const ipfs = create ({ host: ' 1.1.1.1' , port: ' 80' , apiPath: ' /ipfs/api/v0' })
281
279
```
282
280
283
281
### In a web browser
@@ -334,7 +332,7 @@ const ipfs = window.IpfsHttpClient()
334
332
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:
335
333
336
334
``` js
337
- const ipfs = ipfsClient ({
335
+ const ipfs = create ({
338
336
host: ' localhost' ,
339
337
port: 5001 ,
340
338
protocol: ' http' ,
@@ -350,9 +348,9 @@ To set a global timeout for _all_ requests pass a value for the `timeout` option
350
348
351
349
``` js
352
350
// Timeout after 10 seconds
353
- const ipfs = ipfsClient ({ timeout: 10000 })
351
+ const ipfs = create ({ timeout: 10000 })
354
352
// Timeout after 2 minutes
355
- const ipfs = ipfsClient ({ timeout: ' 2m' })
353
+ const ipfs = create ({ timeout: ' 2m' })
356
354
// see https://www.npmjs.com/package/parse-duration for valid string values
357
355
```
358
356
0 commit comments