Skip to content
This repository has been archived by the owner on Apr 24, 2021. It is now read-only.

A Koa module that allows predefinition of custom HTTP codes and messages that can then be used in Koa responses.

License

Notifications You must be signed in to change notification settings

srinivasiyer/koa-custom-statuses

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Koa Custom Statuses

NPM version build status Test coverage David deps iojs version node version npm download

Koa has a defined set of HTTP response codes that can be retured in a request. While they are shandard HTTP codes and will be enough most of the time, Sometimes, there is a need for creating custom codes. This module enables you to achieve just that declaring the additional codes you require in the very beginning. It also enables you to change the status message of existing status codes.

The module definition is extremely simple. Just wrap a koa function into the module along with an object containing the status code you require.

var koa = require('koa')
var app = koa()
require('koa-custom-statuses')(app, {
    '200': 'Im Loving it!!',
    '499': 'Cos I can come that close to 500',
    '700': 'Theres the 7 series in HTTP',
    '999': 'Because We can'
});

app.use(funcion(){
    //This will no longer throw an invalid code error
    this.status = 700;
})

There are just some basics you need to keep in mind.

  • The status codes can be 3 digit numbers only.
  • The codes you declare will overwrite the Koa Defaults.
  • You can only use default Koa codes or the codes defined in the module. Any others will throw an error

License

MIT

About

A Koa module that allows predefinition of custom HTTP codes and messages that can then be used in Koa responses.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published