2.0.3 • Published 10 years ago

express-status-helper v2.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

Express Status Helper

Simple HTTP staus handling for Express Apps

Use HTTP Status Codes for reference on proper status usage

Installing

In command line: npm install --save express-status-helper

Wherever you use it: var esh = require("express-status-helper");

Usage

esh takes three arguments. You must pass in the response object from express and a staus code. Optionally, you may also include an object with a custom message to be used instead of the preloaded messages and a data object to send back in the json object.

Example Use

var router = express.Router();
var esh = require("express-status-helper");

router.post("/", function(req,res,next) {
	var onSuccess = {
    message: "Hooray! It worked!",
		data: {
      foo: "bar"
    }
	};
  // example request requires "email" key in body
  if (!req.body.email) return esh(res, 400); 
  else return esh(res, 200, onSuccess)
})

Example Responses (for the above example)

{
  "success": false,
  "message": "Authentication failed or not provided"
}
{
  "success": true,
  "message": "Hooray! It worked!",
  "data": {
		"foo": "bar",
	}
}

TODO

  • option to add data upon success responses
  • required header parameters for failure codes (esp. 401, 407, etc.)
  • additional markdown doc with documentation for each status code
2.0.3

10 years ago

2.0.2

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago