jonsamwell / angular-http-batcher

Enables HTTP batch request with AngularJS
MIT License
96 stars 28 forks source link

Adapter for batch-request #40

Open c1moore opened 7 years ago

c1moore commented 7 years ago

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": "victor@socialradar.com",
        "headers": {...}
    },
    "myRequest3": {
        "statusCode": 200,
        "body": "SocialRadar",
        "headers": {...}
    },
}

I might work on a solution for this if I get some time.

c1moore commented 7 years ago

I'm trying to work on this now, but had a few questions.

  1. 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.
  2. 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.
  3. Is order of requests passed to buildRequest() and parseResponse() guaranteed? I need to uniquely identify each request independently of the other using a String or Number key. Since I can use POST 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?