smart-response
v1.0.1
Published
Smart API response wrapper for Express.
Maintainers
Readme
smart response
"smart response" is middleware to standardize success and error responses across all Express APIs
Installation
npm i smart-responseBasic Setup
import express from "express";
import { createResponseHandler } from "smart-response";
const app = express();
app.use(createResponseHandler());
app.get("/", (req, res) => {
try {
const data = { name: "xyz" };
return res.sucess(200, "getting data successfully", data);
} catch (error) {
return res.fail(500, "Internal error", error.message);
}
});
app.listen(3000, () => {
console.log("Server running on 3000");
});success response Output
success: true,
200,
"getting data successfully",
data:{
name:"xyz"
},
}error response Output
success: false,
500,
"Internal error",
error:" ",
}License
This project is licensed under the MIT Licenses
