
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
simplyrest is a REST API Framework based on ExpressJS. simplyrest uses nodeannotations library to provide hassle-free and easy way to expose REST APIs via Annotations.
To Expose a REST API, create a controller class and annotate with the predefined annotations.
Find complete examples in the example folder.
npm install --save simplyrest
let options = {
// Put your options here
};
simplyrest.config(options);
Step 1 : Create a file under the [project root]/controllers folder (or the custom configured controllers folder)
Step 2 : Create a class and Annotate with @Controller
/**
* @Controller("/")
*/
class MyController {
}
NOTE :
Step 3 : Create functions and annotate with supported HTTP Method to expose it as a REST API.
/**
* @Controller("/")
*/
class MyController {
/**
* @Get("/")
*/
rootMethod(req, res, next) {
res.send("Welcome");
}
/**
* @Get("helloWorld/")
*/
helloWorld(req, res, next) {
res.send("Hello World");
}
}
NOTE :
simplyrest expects the method signature to be (req, res, next) just like ExpressJS Router Methods.router.paramrouter.param functionality is supported via @Param(paramName) Annotation.
Example :
/**
* @Controller("/")
*/
class MyController {
/**
* @Get("/printName/:name")
*/
rootMethod(req, res, next) {
res.send("Welcome "+req.params.name);
}
/**
* @Param("name")
*/
paramNameHandler(req, res, next) {
console.log("Route with Param name called...");
next();
}
}
To add a middleware, call the use function with an Express Middleware.
simplyrest.use((req, res, next) => {
console.log("Middleware called");
});
Any Templating Engine can be used to render the templates.
npm install --save pugviewEngine to pug in the options.let options = {
[...]
"viewEngine": "pug",
[...]
};
simplyrest.config(options);
To add an error handler, call the errorHandler function with an Express Error Handler.
simplyrest.errorHandler((err, req, res, next) => {
res.send(err.message);
});
If no error handler is supplied, by default an error handler is attached with the server which will display the error status, error message and error stack. The following error handler is added by default :
(err, req, res, next) => {
res.status(err.status || 500);
res.send(`<h1>${err.message}</h1><h2>${err.status}</h2><pre>${err.stack}</pre>`);
};
The simplyrest Server can be started by calling the listen function.
The server will listen on port provided via options if no argument is passed while calling listen(). If port is not configured via options, then the server will listen on the default port 3000.
simplyrest.listen();
The server will listen on port provided via argument even when the port is configured via options.
simplyrest.listen(8080);
Find two complete examples in the examples folder.
options <Object>
controllersPath : Relative Path to Controllers Folder
"/controllers"viewsPath : Relative Path to Views Folder
"/views"publicPath : Relative Path to Public Folder
"/public"viewEngine : Templating engine to Render the Templates
"ejs"port Port on which the server will listen
3000middleware : Expects an Express Middleware
handler : Expects an Express Error Handler
port : Port on which the server will listen
FAQs
Simplest REST Api Framework for NodeJS
We found that simplyrest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.