salak-curl
v1.0.5
Published
curl for salak 2.0
Downloads
359
Maintainers
Readme
salak-curl
CURL for salak 2.0
Install
$ npm install --save salak-curl
Usage
Config
In plugin:
module.exports = {
plugin: [
{
name: 'curl',
package: 'salak-curl'
}
]
}
options
- headers {Object}
- body {Object}
- query {Object}
- contentType {String} json,form
- retry {Integer} default 0
- timeout {Integer}
- method {String} default
GET
- dataType {String} if set to 'json', it could parse the res.text to json, while error occurred, the output.err would be shown.
- plugins {Array} ref to superagent plugins, [{ plugin: Object, options: {} }]
app, ctx, Base.prototype
curl (url, options)
- options {Object} the same as above properties except
plugins
. if unset, would use the default properties which provided at above. - options.stream {Stream} response stream, if set, will run
req.pipe(stream)
- options.reqStrem {Stream} request stream, if set, will run
reqStream.pipe(req)
- @return Promise
Use in Service or Controller
common/service/user.js
const { Service } = require('salak')
class Data extends Service {
async test () {
const data = await this.curl('http://xxx.xxx')
return data
}
}
module.exports = Data