You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 11, 2022. It is now read-only.
This library can be used with one of three `request` plugins:
213
+
214
+
1.`default` - the default [request](https://www.npmjs.com/package/request) library plugin. This uses Node.js's callbacks to communicate Cloudant's replies
215
+
back to your app and can be used to stream data using the Node.js [Stream API](https://nodejs.org/api/stream.html).
216
+
2.`promises` - if you'd prefer to write code in the Promises style then the "promises" plugin turns each request into a Promise. This plugin cannot be used
217
+
stream data because instead of returning the HTTP request, we are simply returning a Promise instead.
218
+
3.`retry` - on occasion, Cloudant's multi-tenant offerring may reply with an HTTP 429 response because you've exceed the number of API requests in a given amount of time.
219
+
The "retry" plugin will automatically retry your request with exponential back-off.
220
+
4. custom plugin - you may also supply your own function which will be called to make API calls.
221
+
222
+
#### The 'promises' Plugins
223
+
224
+
When initialising the Cloudant library, you can opt to use the 'promises' plugin:
225
+
226
+
```js
227
+
var cloudant =Cloudant({url: myurl, plugin:'promises'});
228
+
var mydb =cloudant.db.use('mydb');
229
+
```
230
+
231
+
Then the library will return a Promise for every asynchronous call:
232
+
233
+
```js
234
+
mydb.list().then(function(data) {
235
+
console.log(data);
236
+
}).catch(function(err) {
237
+
console.log('something went wrong', err);
238
+
});
239
+
```
240
+
241
+
#### The 'retry' plugin
242
+
243
+
When initialising the Cloudant library, you can opt to use the 'retry' plugin:
244
+
245
+
```js
246
+
var cloudant =Cloudant({url: myurl, plugin:'retry'});
247
+
var mydb =cloudant.db.use('mydb');
248
+
```
249
+
250
+
Then use the Cloudant library normally. You may also opt to configure the retry parameters:
251
+
252
+
- retryAttempts - the maximum number of times the request will be attempted (default 3)
253
+
- retryTimeout - the number of milliseconds after the first attempt that the second request will be tried; the timeout doubling with each subsequent attempt (default 500)
254
+
255
+
```js
256
+
var cloudant =Cloudant({url: myurl, plugin:'retry', retryAttempts:5, retryTimeout:1000 });
257
+
var mydb =cloudant.db.use('mydb');
258
+
```
259
+
260
+
#### Custom plugin
261
+
262
+
When initialising the Cloudant library, you can supply your own plugin function:
263
+
264
+
```js
265
+
vardoNothingPlugin=function(opts, callback) {
266
+
// don't do anything, just pretend that everything's ok.
267
+
callback(null, { statusCode:200 }, { ok:true});
268
+
};
269
+
var cloudant =Cloudant({url: myurl, plugin: doNothingPlugin});
270
+
```
271
+
272
+
Whenever the Cloudant library wishes to make an outgoing HTTP request, it will call your function instead of `request`.
0 commit comments