Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-custom-response

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-custom-response - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

4

lib/default/ok.js

@@ -6,6 +6,6 @@ /**

module.exports = function(data){
module.exports = function(extra){
// Set status code
this.status(200);
this.send(data || {});
this.send(extra || {});
}

@@ -8,7 +8,7 @@ /**

// Set status code
this.status(400);
this.status(500);
this.send({
error: {
error_message: 'We\'re sorry, a server error occurred. Please wait a bit and try again',
error_code: 400,
error_code: 500,
error_extra: extra || null

@@ -15,0 +15,0 @@ }

{
"name": "express-custom-response",
"description": "Create custom response methods for express.js",
"version": "0.1.0",
"version": "0.1.1",
"homepage": "https://github.com/fireridlle/express-custom-response",

@@ -6,0 +6,0 @@ "author": {

@@ -8,21 +8,80 @@ # express-custom-response

##Quick Start
```javascript
var express_custom_response = require('express-custom-response');
express_custom_response.awesome(); // "awesome"
require('express-custom-response')();
```
## Documentation
_(Coming soon)_
Module contain pre-defined custom responses:
## Examples
_(Coming soon)_
**res.serverError (extra)**
- *mixed* **extra**
- Any data that have to be returned to user
> return reponse with http code 500 and body:```
error: {
error_message: 'We're sorry, a server error occurred. Please wait a bit and try again',
error_code: 500,
error_extra: null or extra
}
```
## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
**res.forbidden (fields, extra)**
- *object* **fields**
- Object which contain validation error, where key is field name and value is message
- *mixed* **extra**
- Any data that have to be returned to user
> return reponse with http code 405 and body:```
error: {
error_message: 'Validation failed',
error_code: 405,
fields: {email: 'Email has to be uniq'},
error_extra: null or extra
}
```
## Release History
_(Nothing yet)_
**res.notFound (name, extra)**
- *string* **name**
- What server can't find
- *mixed* **extra**
- Any data that have to be returned to user
> return reponse with http code 404 and body:```
error: {
error_message: 'User not found',
error_code: 404,
error_extra: null or extra
}
```
## License
Copyright (c) 2015 Sergii Zinkevych
Licensed under the MIT license.
**res.ok (extra)**
- *mixed* **extra**
- Any data that have to be returned to user
> return reponse with http code 404 and body:```
{} or extra
```
## Create own response
If you want to add you own responses you should pass absolute path to module constructor
```javascript
require('express-custom-response')(__dirname+ '/api/responses');
```
Then each script in this directory will be available as response method by filename. Example:
```javascript
/**
* api/responses/accepted.js
*
* This will be available in controllers as res.accepted(message);
*/
module.exports = function(redirectTo, extra){
//this is points to express.response
this.status(202);
this.send(message);
}
```
If you want to override exists pre-defined response simple add new script to your directory with name of response which you want to override
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc