https://github.com/ttionya/egg-got
HTTP request library (got) plugin for EggJS.
https://github.com/ttionya/egg-got
Last synced: 8 months ago
JSON representation
HTTP request library (got) plugin for EggJS.
- Host: GitHub
- URL: https://github.com/ttionya/egg-got
- Owner: ttionya
- License: mit
- Created: 2020-03-29T11:59:41.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-29T12:03:13.000Z (over 5 years ago)
- Last Synced: 2025-01-05T00:19:21.077Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# egg-got
[![NPM version][npm-image]][npm-url]
[npm-image]: https://img.shields.io/npm/v/egg-got.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-got>
> ### Important:
>
> **still in develop, do not use in production.**
>HTTP request library [got](https://github.com/sindresorhus/got) plugin for [eggjs](https://github.com/eggjs/egg).
## Install
```bash
$ npm i egg-got
```## Usage
```js
// {app_root}/config/plugin.js
exports.got = {
enable: true,
package: 'egg-got',
};
```## Configuration
```js
// {app_root}/config/config.default.js
exports.got = {
// ...
};
```If you want to save `got` log, please define a custom logger named `gotLogger`, this name you can rename in `got.logger.name`.
```js
// custom logger
exports.customLogger = {
gotLogger: {
// ...
},
};
```### Options:
You can use [got options](https://github.com/sindresorhus/got#options) in root property, but exclude `hooks`, you should `got.extend` it yourself.
#### `logger.name`
Type: `string`
The custom logger name.
#### `logger.formatter`
Type: `Function`
See [got hooks](https://github.com/sindresorhus/got#hooks) for more detail.
For example:
```js
/**
* @param {Object} data
* @param {string} data.type
* @param {Object} data.options
* @param {Object} data.response
* @param {Object} data.error
* ...
*/
function formatter(data) {
switch (data.type) {
case 'init': {
const { options } = data;
// ...
}
case 'beforeRetry': {
const { options, error, retryCount } = data;
// ...
}
case 'beforeError':
case 'beforeRequest':
case 'afterResponse':
case 'beforeRedirect':
}
}
```## License
[MIT](LICENSE)