1.0.5 • Published 3 years ago

salak-curl v1.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

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

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago