0.0.2 • Published 12 years ago
batch-endpoint v0.0.2
Restify batch endpoint
An endpoint for batch-querying GET endpoints on a restify server.
Usage
Once setup, you'll be able to do the following call:
GET /batch?pages=/&pages=/page1&pages=/page2And receive the following response:
{
"/": "result from / call",
"/page1": "result from /page1 call",
"/page2": "result from /page2 call",
}When an error occurs in one endpoint, HTTP status code is piggybacked to the main request, and an errored key appear with the invalid page. All other pages will still be loaded.
Implementation
var restify = require('restify');
var batchEndpoint = require('batch-endpoint');
// Initialize server
server = restify.createServer();
server.use(restify.queryParser());
server.get('/endpoint', handlerFunction);
// ... other routes...
server.get('/batch', batchEndpoint(server));Parameters
require("batch-endpoint") takes two parameters:
server, the restify (or HTTP) server to use forGETqueries. This parameter can be lazy loaded (wrap it in a function which return the server) to avoid circular dependencies in some use-cases.options, a configuration hash with the following keys:maxPages: page limit per queries. Default to 9.concurrency: internally, the number of calls to do simultaneously to generate the query. Default tomaxPagesforwardAuthorizationHeader: whether all queries should forward theAuthorizationheader sent to the batch endpoint.
