rest - Batching API requests with flask-restful -
rest - Batching API requests with flask-restful -
i'm building rest api flask-restful , 1 thing i'd enable ability batch request resources, similar how facebook graph api works:
curl \ -f 'access_token=…' \ -f 'batch=[{"method":"get", "relative_url":"me"},{"method":"get", "relative_url":"me/friends?limit=50"}]' \ https://graph.facebook.com
which returns array each request resolved status code , result:
[ { "code": 200, "headers":[ { "name": "content-type", "value": "text/javascript; charset=utf-8" } ], "body": "{\"id\":\"…\"}"}, { "code": 200, "headers":[ { "name":"content-type", "value":"text/javascript; charset=utf-8"} ], "body":"{\"data\": [{…}]}} ]
i've been able replicate in flask-restful looping on requests , calling urlopen against own app. seems inefficient , have think there's improve way. there simpler and/or improve way create requests against own application within request handler?
since need homecoming headers recommendation send these batched requests (i.e. send requests localhost
), way responses consistent when making individual calls.
consider when api receives batch request need @ to the lowest degree 1 free worker take on these indirect requests while first worker blocks , waits. need have @ to the lowest degree 2 workers. risk deadlock, if 2 batch requests arrive @ same time , take 2 workers. in reality need have many workers batch requests expect receive concurrently plus @ to the lowest degree 1 more handle indirect requests.
looking @ side, want run many of these indirect requests in parallel, because if end running 1 after benefit of using batch requests lost. need have sufficient number of workers allow parallelism.
in honesty don't see great feature. in client-side languages easy execute several requests in parallel, don't need provide server-side feature. specially easy if using javascript, easy in python, ruby, etc.
rest flask flask-restful
Comments
Post a Comment