Home

Awesome

koa-custom-response

Coverage Status travis-ci MIT

standard and convenient custom responses. focus on simplifying your code logic, reduce your controller. you just need a line of code to return the standard data and status code.

<br>

Usage

<br>

API

Method (ctx.{method_name})paramsaction
okdata: object or stringset http status to 200, return json (default: {})
createddata: object or stringset http status to 201, return json (default: {})
noContentno paramsset http status to 204, return null
serverErrordata: object or stringset http status to 500, return json (default: {})
notFounddata: object or stringset http status to 404, return json (default: {})
forbiddendata: object or stringset http status to 403, return json (default: {})
badRequestdata: object or stringset http status to 400, return json (default: {})
catcherr: Error, data: object or stringset http status to 501, return error
replycode: number, data: object or stringset http status with code

if the parameter is a string, will return { message: str }, like:

server: ctx.notFound('not found anything')

client response: { message: 'not found anything' }

<br>

Examples

example

<br>

LICENSE

MIT