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
Copy file name to clipboardExpand all lines: README.md
+37-17
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,26 @@ Feel free to get involved in development.
13
13
## Issues, Features and Bugs
14
14
This has been created for an internal project of [wapisasa](https://github.com/wapisasa) so it might not fit everyone's requirements. It might also be buggy as it's an alpha release. Any issues, feature requests or bugs that need attention please [let us know](https://github.com/wapisasa/batchelor/issues).
15
15
16
+
## Upgrading to 1.0
17
+
18
+
The API was changed in 1.0 to move from a singleton instance to a constructor. So before where you used `Batchelor` directly:
19
+
20
+
```node
21
+
var Batchelor =require('batchelor')
22
+
Batchelor.init(...)
23
+
Batchelor.add(...)
24
+
Batchelor.run(...)
25
+
```
26
+
27
+
You now need to create an instance of Batchelor:
28
+
29
+
```node
30
+
var Batchelor =require('batchelor')
31
+
var batch =newBatchelor(...)
32
+
batch.add(...)
33
+
batch.run(...)
34
+
```
35
+
16
36
## Installation
17
37
18
38
This library has also been distributed on `npm`. Install it with the following command:
@@ -21,14 +41,16 @@ This library has also been distributed on `npm`. Install it with the following c
21
41
$ npm install batchelor --save
22
42
```
23
43
44
+
See <https://github.com/wapisasa/batchelor/issues/4> for why this change was made.
45
+
24
46
## How to Use
25
47
#### GET Requests
26
48
```node
27
49
var Batchelor =require('batchelor');
28
50
```
29
51
Once the module has been included, we initialise it with all our default options:
30
52
```node
31
-
Batchelor.init({
53
+
var batch =newBatchelor({
32
54
'uri':'https://www.googleapis.com/batch',
33
55
'method':'POST',
34
56
'auth': {
@@ -43,14 +65,14 @@ We can then start adding requests to our batch. This can be done 2 ways:
Once you have added all of the requests you need, call `.run()`:
69
91
```node
70
-
Batchelor.run(function(response){
92
+
batch.run(function(response){
71
93
res.json(response);
72
94
});
73
95
```
74
96
#### POST Requests
75
97
The above examples show `GET` requests. To perform a `POST` requires a few more settings:
76
98
```node
77
-
Batchelor.add({
99
+
batch.add({
78
100
'method':'POST',
79
101
'path':'/plusDomains/v1/people/me/activities',
80
102
'parameters':{
@@ -84,9 +106,9 @@ Batchelor.add({
84
106
});
85
107
```
86
108
#### Callbacks
87
-
By default, all responses are returned through the callback function in the `Batchelor.run()` call. Alternatively, a callback can be supplied for each individual calls:
109
+
By default, all responses are returned through the callback function in the `batch.run()` call. Alternatively, a callback can be supplied for each individual calls:
88
110
```node
89
-
Batchelor.add({
111
+
batch.add({
90
112
'method':'POST',
91
113
'path':'/plusDomains/v1/people/me/activities',
92
114
'parameters':{
@@ -99,22 +121,20 @@ Batchelor.add({
99
121
});
100
122
```
101
123
#### Request and Response IDs
102
-
The module will assign a request a randomly generated unique `Content-ID` by default, but this can be supplied as part of the options to supply `Batchelor.add()`:
124
+
The module will assign a request a randomly generated unique `Content-ID` by default, but this can be supplied as part of the options to supply `batch.add()`:
All methods return the `Batchelor`object. So you can chain calls together.
134
+
All methods return the `Batchelor`instance. So you can chain calls together.
113
135
114
136
```node
115
-
Batchelor.init({
116
-
...
117
-
}).add([
137
+
batch.add([
118
138
...
119
139
]).run(function(data){
120
140
...
@@ -123,7 +143,7 @@ Batchelor.init({
123
143
###### Data Pass-through
124
144
When passing options to the `.add()` you can include an Object called `extend`. In the case of providing a callback, this will be passed back as a second parameter. When using the default callback on the `.run()` call, an array of all data passed through will be added as a second parameter with the requestId as the key:
125
145
```node
126
-
Batchelor.add({
146
+
batch.add({
127
147
...
128
148
'extend':{
129
149
...
@@ -136,12 +156,12 @@ Batchelor.add({
136
156
This could be required, for example, when making multiple requests with different Auth data and then needing to make further requests with the same Auth data.
137
157
138
158
###### Resetting and Re-using
139
-
Once Batchelor has been run, there are certain use-cases for running futher batch requests on response. This requires the variables in the module to be reset. This can be done using the `.reset()` call:
159
+
Once Batchelor has been run, there are certain use-cases for running futher batch requests on response. This requires the variables in the instance to be reset. This can be done using the `.reset()` call:
0 commit comments