rcs-jsonstyle
v1.0.3
Published
Small Module To standardize Json responses from servers
Downloads
1
Readme
Json Style
A Json Response module for ExpressJS. Used by Red Carpet Solutions To standardize Json Responses from the server
Installation
npm i -S rcs-jsonstyle
How to Use
This Module only works with ExpressJS. Once you have your ExpressJS Application, It's actually fairly simple:
const express = require('express');
var app = express();
// Standard express App Declaration
const rcsres = require('rcs-jsonstyle');
// Require the module
//Write your standart ExpressJS Middleware
app.get('/someroutes',(req,res)=>{
var data = ImportFromDatabase() // Dummy Function
if(data){
rcsres.json(res, data); // Pass in the response and the data
// And You're Done
} else {
rcsres.error(res, "SOME ERROR MESSAGE"); // Send an Error response
// Error response have status code 500 and a diffrent format
}
});
you can check the modules/res.module.js file to see all the responses available (We covered the most frequent ones)
More Responses
Please leave an Issue with the response you want and we will add it to the library. Issues
Red Carpet Solutions
We're a Company What do we do!
This project is backed By redcarpetsolutions
About the Author
I'm Khaled Romdhane but mostly known as heiyuki. My handle is : @heiyukidev.
I Work at this amazing Company @redcarpetsolutions don't hesitate to go check us out.