Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhangmingfeng/egg-curl
egg curl httpclient plugin
https://github.com/zhangmingfeng/egg-curl
curl egg-plugin httpclient
Last synced: about 2 months ago
JSON representation
egg curl httpclient plugin
- Host: GitHub
- URL: https://github.com/zhangmingfeng/egg-curl
- Owner: zhangmingfeng
- License: mit
- Created: 2018-09-10T10:10:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-10T10:11:10.000Z (over 6 years ago)
- Last Synced: 2024-11-20T10:52:18.831Z (2 months ago)
- Topics: curl, egg-plugin, httpclient
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# egg-curl
该插件是对egg自带的httpClient的封装,使用更简洁的api进行http请求,目前提供get, post, put 方法,后续有需要在增加其他方法# Install
```bash
$ npm i --save egg-curl
```## Usage & configuration
- `config.default.js`
```js
exports.curl = {
defContentType: 'application/json; charset=UTF-8', //默认的Content-Type
defDataType: 'text', // 默认的dataType
timeout: [10000, 10000] //连接和返回的超时时间
};
```- `config/plugin.js`
``` js
exports.curl = {
enable: true,
package: 'egg-curl'
}
```### example
```js
// controller.js or service.js post请求
const result = await this.ctx.curlPost(`http://api.com/v1/api/user/login`, {
account: 'test',
password: '123456'
});```
```js
// controller.js or service.js get请求
const result = await this.ctx.curlGet(`http://api.com/v1/api/user/1`);```
### api
- curlGet(url, data, header);
- curlPost(url, data, header);
- curlPut(url, data, header);