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
Basic API
request('url')
request({options})
request('url', function callback (err, res, body) {})
request({options}, function callback (err, res, body) {})
request('url', {options}, function callback (err, res, body) {})
request[HTTP_VERB]('url')
request[HTTP_VERB]({options})
request[HTTP_VERB]('url', function callback (err, res, body) {})
request[HTTP_VERB]({options}, function callback (err, res, body) {})
request[HTTP_VERB]('url', {options}, function callback (err, res, body) {})
var api = require('@request/api')
var client = require('@request/client')
// initialize the API
var request = api({
type: 'basic',
// pass HTTP request function
// that accepts @request/interface options
request: client
})
// GET http://localhost:6767?a=1
request.get('http://localhost:6767', {qs: {a: 1}}, (err, res, body) => {
// request callback
})
Chain API
var api = require('@request/api')
var client = require('@request/client')
// initialize the API
var request = api({
type: 'chain',
// API methods configuration
config: {
// HTTP methods
method: {
get: ['select'],
// ...
},
// @request/interface option methods
option: {
qs: ['where'],
// ...
},
// custom methods
custom: {
request: ['fetch', 'snatch', 'submit'],
// ...
}
},
// custom methods implementation
define: {
// pass any arguments to your custom methods
request: function (callback) {
if (callback) {
// `this._options` contains the generated options object
this._options.callback = callback
}
// the last method should return @request/interface consumer
return client(this._options)
// or
return this // if you want to chain further
}
}
})
// GET http://localhost:6767?a=1
request
.select('http://localhost:6767')
.where({a: 1})
.fetch((err, res, body) => {
// request callback
})