angular-http-batcher
angular-http-batcher copied to clipboard
Adapter for batch-request
As far as I have been able to find, batch-request is one of the most full-featured batch request libraries available for Node.js.
The format for the request looks like
{
"myRequest1": {
"method": "GET",
"uri": "http://api.mysite.com/users/1/first_name"
},
"myRequest2": {
"method": "GET",
"dependency": "myRequest1",
"uri": "http://api.mysite.com/users/1"
},
"myRequest3": {
"method": "GET",
"uri": "http://api.mysite.com/users/1/company"
},
}
While the response may look something like
{
"myRequest1": {
"statusCode": 200,
"body": "Victor",
"headers": {...}
},
"myRequest2": {
"statusCode": 200,
"body": "[email protected]",
"headers": {...}
},
"myRequest3": {
"statusCode": 200,
"body": "SocialRadar",
"headers": {...}
},
}
I might work on a solution for this if I get some time.
I'm trying to work on this now, but had a few questions.
-
Are
$http
interceptors processed for each individual request or are they processed only for the batch request? Unfortunately,batch-request
doesn't allow headers to be inherited by the individual requests, so headers appended to requests by interceptors must be processed before building the batch request. -
Does the URL for GET requests contain the serialized params or does this need to be processed by
buildRequest()
?batch-request
requires the URL to appear in the request body, so Angular won't have a chance to serialize the data if it hasn't done so by the time I start building the batch request. -
Is order of requests passed to
buildRequest()
andparseResponse()
guaranteed? I need to uniquely identify each request independently of the other using a String or Number key. Since I can usePOST
requests, the *best approach might be to use the index of the request, if order is guaranteed. If not, can I add a new field to the requests?