salak-curl

1.0.5 • Public • Published

salak-curl

NPM version build status David deps NPM download

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

License

MIT

Package Sidebar

Install

npm i salak-curl

Weekly Downloads

6

Version

1.0.5

License

MIT

Unpacked Size

151 kB

Total Files

24

Last publish

Collaborators

  • wengeek