Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yeliex/koa-response
Response Middleware for koajs
https://github.com/yeliex/koa-response
Last synced: about 2 months ago
JSON representation
Response Middleware for koajs
- Host: GitHub
- URL: https://github.com/yeliex/koa-response
- Owner: yeliex
- License: mit
- Created: 2016-06-07T08:13:42.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-22T05:48:48.000Z (over 6 years ago)
- Last Synced: 2024-10-31T17:02:25.911Z (2 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-response
Response Middleware for koajs
[![npm](https://img.shields.io/npm/v/koa-response.svg?style=flat-square)](https://www.npmjs.com/package/koa-response)
## Installation
```
$ npm install koa-response
```## koa@2
```
$npm install koa-response@next
```## Usage
```js
const app = require('koa')();
const response = require('koa-response');app.use(response((responsed) => {console.log(responsed.method,request.body)}));
app.use(function *(next){
this.throw(200,success);
});
```## API
```js
this.throw(status,data/error,isjson);- status: 状态码,400以下为成功
- data/error: 返回的数据/错误
- 当返回失败(status>=400 || status === false),且没有指定error时,默认返回默认错误
- isjson: 是否已json格式返回,默认true
- false时返回类似nginx错误的html```