2.1.1 • Published 4 years ago

trooba-http-api v2.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

trooba-http-api

codecov Build Status NPM Downloads Known Vulnerabilities

Provides a generic transport API to http/ajax/xhr trooba transports.

Get Involved

  • Contributing: Pull requests are welcome!
  • Support: Join our gitter chat to ask questions to get support from the maintainers and other Trooba developers

Install

npm install trooba-http-api --save

Usage

Export via transport

var Wreck = require('wreck');
var _ = require('lodash');

var httpfy = require('trooba-http-api');

module.exports = function transport(pipe, config) {
    pipe.on('request', function (request) {
        request = _.merge(request || {}, config);
        Wreck.request(request, function onResponse(err, response) {
            if (err) {
                pipe.throw(err);
                return;
            }
            pipe.respond(response);
        });
    });

    // inject api
    pipe.set('client:default', httpfy);
};

Attach to any pipe

var Trooba = require('trooba');

var client = new Trooba()
.use(function someHandler() {})
.use(function someHandler() {})
.use(function someHandler() {})
.use('trooba-http-api')
.build()
.create('client:default'); // since it injects default at ''client:default''

client.delete('path/to/resource').end(console.log);
2.1.1

4 years ago

2.1.0

5 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago