jonsamwell / angular-http-batcher

Enables HTTP batch request with AngularJS
MIT License
96 stars 28 forks source link

Usage with NodeJS #19

Closed tamlyn closed 9 years ago

tamlyn commented 9 years ago

There are many batch request handlers for NodeJS (e.g. multifetch, batch-endpoint, express-batch) but they batch requests by specifying them in the query string and combining the JSON responses in the body. I can't seem to find any that support multipart/mixed responses. Would you consider adding support for this alternate batching format? Or perhaps provide callbacks to allow customising the batching and unwrapping strategy?

jonsamwell commented 9 years ago

Hi @tamlyn,

Yeah I'd definitely want to add support for this. Could you provide any example or better yet a node project (like the .net one) that has a batch endpoint that we help me develop and test against?

Thanks,

Jon

jonsamwell commented 9 years ago

@tamlyn any progress on this?

jonsamwell commented 9 years ago

Hopefully this is working now in the v1.11.0 release!

You will need to update your config object slightly to use the multifetch batch adapter and it should work after that.

app.config([
            'httpBatchConfigProvider',
            function (httpBatchConfigProvider) {
                httpBatchConfigProvider.setAllowedBatchEndpoint(
                        'http://localhost:8080',
                        'http://localhost:8080/batch', {
                            batchRequestCollectionDelay: 500,
                            minimumBatchSize: 1,
                            ignoredVerbs: ['head', 'post', 'put', 'delete', 'patch'],
                            adapter: 'nodeJsMultiFetchAdapter'
                        });
            }
    ]);

see the test page

https://github.com/jonsamwell/angular-http-batcher/blob/master/tests/node-multi-fetch.html

see the adapter here

https://github.com/jonsamwell/angular-http-batcher/blob/master/src/services/adapters/nodeJsMultiFetchAdapter.js

Let me know if it works and suits your needs!

tamlyn commented 9 years ago

Coooool!