Package Exports
- @request/api
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@request/api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@request/api
Use this module to create sugar API for your HTTP client. You can also allow your users to define their own method aliases.
var api = require('@request/api')
var client = require('@request/client')
// all API methods and their aliases
var config = {
// HTTP methods
method: {
get: ['select']
},
// @request/core option methods
option: {
qs: ['where'],
callback: ['done']
},
// custom methods
custom: {
check: [],
submit: ['gimme']
}
}
// custom method implementation
var custom = {
// `host` is parameter passed to your method
check: function (options, host) {
if (/localhost/.test(host)) {
options.url += ':6767'
}
// `this` contains the API itself, for chaining purposes
return this
},
// `options` contains the generated options object from the preceding methods
submit: function (options) {
// the last method should return a @request/core consumer
return client(options)
}
}
var request = api(config, custom)
// GET http://localhost:6767?a=b
request
.select('http://localhost')
.check('localhost')
.where({a: 'b'})
.done((err, res, body) => {
// request callback
})
.gimme()
See @request/core for more details.