batch http requests

后端 未结 7 1900
[愿得一人]
[愿得一人] 2021-02-01 06:31

Does anyone know a standard way to batch http requests? Meaning - sending multiple http atomic requests in one round trip?

We need such mechanism in our REST API implem

相关标签:
7条回答
  • 2021-02-01 07:12

    CURL

    The build 17063 of windows 10 (and the following versions) are coming with CURL command:

    curl -X POST -H "Content-Type: application/json" -d "{\"name\": \"myname\", \"email\": \"some@example.com\"}' https://example/contact
    

    winHttpJs.bat

    call winhttpjs.bat "http://requestb.in/xxxxxx" -method POST -header hdrs.txt -reportfile reportfile2.txt
    
    call winhttpjs.bat "http://requestb.in/xxxxxx" -method GET -header hdrs.txt -reportfile reportfile3.txt -saveTo c:\somezip.zip 
    
    call winhttpjs.bat "http://requestb.in/xxxxxx" -method POST -header hdrs.txt -reportfile reportfile2.txt -saveTo responsefile2 -ua "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"  -body-file some.json
    

    It does not support multi-part requests at the moment ,i'm planning to add such a thing but I don't know when i'll have the time.

    0 讨论(0)
  • 2021-02-01 07:14

    If using dedicated 'aggregate' resources as fumanchu said above does not work for you, you can also try if you can move representations of less volatile resources to caches to reduce load on your system. For example: HTML pages on the 'human' Web often include loads and loads of images and the many sub request are of no concern there.

    0 讨论(0)
  • 2021-02-01 07:14

    You create batch requests by calling new_batch_http_request() on your service object, which returns a BatchHttpRequest object, and then calling add() for each request you want to execute. You may pass in a callback with each request that is called with the response to that request. The callback function arguments are a unique request identifier for each API call, a response object which contains the API call response, and an exception object which may be set to an exception raised by the API call. After you've added the requests, you call execute() to make the requests. The execute() function blocks until all callbacks have been called.

    References:

    You can try this too https://developers.google.com/api-client

    library/python/guide/batch

    https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch

    0 讨论(0)
  • 2021-02-01 07:16

    That's a problem with REST. They are at entity level. The REST idea is to have each URL uniquely identify a resource. Of course you can introduce aggregated resource. For ex, www.yoursite.com/customerA?include=Orders,Faults,Incidents This returns the XML for CustomerA but also returns the Orders, faults, Incidents of the customer as embedded collection.

    0 讨论(0)
  • 2021-02-01 07:22

    Define a new resource that contains the data the client wants. See http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven#comment-743

    0 讨论(0)
  • 2021-02-01 07:22

    If you're looking at REST based services or an API of some kind. There is some beginnings of a standard here http://www.odata.org/documentation/odata-version-3-0/batch-processing/

    And an implementation by Google here https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch

    0 讨论(0)
提交回复
热议问题