オレオレJSON-RPCライブラリがバッチリクエストに対応していなかったので対応した。こんな風に書けるようになった。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | $.jsonrpc.defaultUrl = '/rpc' ; // Send 3 requests at once. $.jsonrpc([{ method: 'getEventStatus' }, { method: 'getUserStatus' }, { method: 'sendLoginStatus' , params: {status: 'login' } }]).done( function (responses) { results.forEach( function (response) { if (response.result) { doSomething(response.result); } else { handleError(response.error); } }); }).fail( function (error) { // timeout or 503 or bad response }); |
hagino3000/jquery-jsonrpc2.0
https://github.com/hagino3000/jquery-jsonrpc2.0
https://github.com/hagino3000/jquery-jsonrpc2.0
なぜ今になってメンテしたかというと、モバイルアプリはクライアントが任意に複数のAPIコールを一つのHTTPリクエストに纏められた方が良いよねと最近思う様になった*1
のと、今日のYAPCのセッションでJSON-RPCのバッチリクエストについて説明があったので。YAPCの感想はまた次のエントリで。
あとbowerのリポジトリを眺めていたら、WebSocketを使う物を見つけたのでこちらの方がおすすめです。
あとbowerのリポジトリを眺めていたら、WebSocketを使う物を見つけたのでこちらの方がおすすめです。
Textalk/jquery.jsonrpcclient.js
https://github.com/Textalk/jquery.jsonrpcclient.js
https://github.com/Textalk/jquery.jsonrpcclient.js
脚注:
*1: Orreily「ハイパフォーマンスブラウザネットワーキング」の影響