Skip to content

Batch Request Update #338

Closed
Closed

Description

@jamesmhaley

As mentioned in Issue #290 batch requests were removed with the idea to introduce a new updated way of performing batch requests.

Any update on this? If not, what is the alternative? I potentially need to do 100s of calls via a service account to retrieve the activities of all the user's in our system.

Activity

  1. edwardysun commented on Jan 21, 2015

    @edwardysun

    +1

  2. wearhere commented on Jan 23, 2015

    @wearhere

    +1

  3. bradvogel commented on Feb 1, 2015

    @bradvogel

    +1

  4. ryanseys commented on Feb 1, 2015

    @ryanseys
    Contributor

    Hi all, does anyone have a suggestion as to how they would like batch requests to function in this library? One of the big issues I've had with batch is how the API would look and function for users so that it's not overly confusing.

  5. wearhere commented on Feb 2, 2015

    @wearhere

    I never used the old batch request API, but it looks wonderfully concise. I really like its principle that API calls return request objects that could (theoretically, again I never used it) be executed singly or be added to the batch request object–i.e. the batch API is very similar to the non-batch API.

    Failing that, I think almost any API would be alright so long as there were code example(s) using the client library. I find Google's HTTP batch request documentation (example) very abstract and have difficulty mapping it to working code.

  6. robertrossmann commented on Feb 2, 2015

    @robertrossmann
    Contributor

    I was thinking the same way - every API call could in the absence of a callback (or explicitly) return an object that fully describes the action to be taken on the remote endpoint - this includes headers, params, message body etc. These objects could then be sent to an aggregator function that takes an array of such requests, generates the batch request, sends it, parses the response back into individual pieces and delivers the results, as an array.

  7. sm-github commented on Feb 3, 2015

    @sm-github

    An API like the front end batch requests would be great!

    gapi client batch

  8. jamesmhaley commented on Feb 3, 2015

    @jamesmhaley
    Author

    I agree with the above points with regards to batching requests. An array based system, with headers/a request id on return would be grand!

    But, also, I guess the dream for me would be the ability to "join" requests as well. You could potentially solve both problems with one nifty solution.

    A use case would be when pulling in Activities: list. An Activity object doesn't always contain all the required data related to that activity. So, I might need to do a separate request for People: listByActivity.

    So a request to Activities: list and then a way to "join" other requests to that request.

    Something like:

    {
        "join":{
            "api":"/people/", // relative API/absolute would both work
            "output":"relatedPeople",
            ...
        }
    }

    Might return something like this:

    {
        "kind": "plus#activity",
        ...
        "relatedPeople":{
            "kind": "plus#peopleFeed",
            ...
        }
    }
  9. ryanseys commented on Feb 3, 2015

    @ryanseys
    Contributor

    @sparkyfied cool idea, this library is meant to be a generic solution for all Google APIs so it will be a little difficult to create those connections with the metadata we are given about the APIs. An array-based system seems like the most do-able here.

    Throwing a code sample out there:

    var google = require('googleapis');
    var drive = google.drive('v2');
    var batcher = google.batcher();
    var aReq1 = drive.files.list({ /* options */ }); // no callback = don't fire request
    var aReq2 = drive.files.list({ /* options */ });
    var aReq3 = drive.files.list({ /* options */ });
    batcher.add(aReq1);
    batcher.add([ aReq2, aReq3 ]);
    batcher.run(function(err, responses) {
      // err: [ error1, null, null ], responses: [ null, response1, response2 ]
    });
  10. wearhere commented on Feb 3, 2015

    @wearhere

    Looks good @ryanseys!

  11. robertrossmann commented on Feb 4, 2015

    @robertrossmann
    Contributor

    Maybe we could even do away without a custom batcher object and instead use arrays directly, then provide that array to some batch request handler:

    var google = require('googleapis')
      , drive = google.drive('v2')
      , reqs = []   // Just an array of requests
    
    // Push individual requests into the array
    reqs.push(drive.files.list({ /* options */ })) // no callback = don't fire request
    reqs.push(drive.files.list({ /* options */ }))
    reqs.push(drive.files.list({ /* options */ }))
    
    // Batch it!
    google.batch(reqs, function (err, responses) { /* magic inside */ })

    Feels more natural to me. Also, this way we would not force people to store the requests in a custom object.

  12. ryanseys commented on Feb 4, 2015

    @ryanseys
    Contributor

    @Alaneor I love it!

  13. ryanseys commented on Feb 4, 2015

    @ryanseys
    Contributor

    I cannot find any documentation on how to create a batch request manually. Can someone link me to some resources?

  14. robertrossmann commented on Feb 4, 2015

    @robertrossmann
    Contributor

    @wearhere posted a link that contained pretty detailed HTTP examples here...

  15. jamesmhaley commented on Feb 4, 2015

    @jamesmhaley
    Author

    +1 all! What are we looking at timeframe wise @ryanseys?

  16. ryanseys commented on Feb 4, 2015

    @ryanseys
    Contributor

    Hey @sparkyfied unfortunately I can't promise anything. I'm a full-time student that works on this in my off-hours so I don't see myself having the time to create this anytime soon (next 3 months), but I'd definitely review and merge PRs that add this functionality. :)

  17. jamesmhaley commented on Feb 5, 2015

    @jamesmhaley
    Author

    Cheers @ryanseys!

  18. jamesmhaley commented on Feb 16, 2015

    @jamesmhaley
    Author

    @ryanseys Not advanced enough with my Node skills to rewrite your API, so needing this feature I created my own module: https://github.com/wapisasa/Batchelor. Everyone feel free to use and get involved if you need extra features. Obviously interested in using an official batching system when available, but this is a good stop-gap in the mean time!

  19. ryanseys commented on Feb 16, 2015

    @ryanseys
    Contributor

    @sparkyfied This is great! Thanks for doing this.

  20. jamesmhaley commented on Feb 16, 2015

    @jamesmhaley
    Author

    @ryanseys 👍 No worries, feel free to make use of it in anyway you require :) And any changes you think it needs, go for it :)

  21. pradeep-mishra commented on May 25, 2015

    @pradeep-mishra

    till it gets implemented in sdk itself try this https://www.npmjs.com/package/google-batch

  22. jrmdayn commented on Jan 10, 2023

    @jrmdayn

    Having hit the issue of batching Google apis requests using Node.js myself, I decided to develop a solution that follows the guidelines provided in Google's batching documentation, implementing the multipart/mixed HTTP request/response protocol.

    Please have a look and do not hesitate to raise an issue if you find a bug or would like to discuss improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions