Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
RouteSmith is a simple routing solution for Express-based apps. It creates routes based off of a list of objects rather than a file structure, allowing you to quickly generate robust routes with easily-assigned controllers, middleware, and parameters.
$ npm install --save routesmith
RouteSmith-Sequelize allows developers to easily create controllers to go along with RouteSmith's routes.
$ npm install --save routesmith-sequelize
const express = require('express');
const router = express.Router();
const routes = require('./routes.js'); // Require your own routes file here.
const rs = require('routesmith');
router.use('/', rs.Initialize(routes)); // Initialize RouteSmith with your route data.
RouteSmith requires an array of JSON objects containing specific information to be defined in order to generate routes.
The path
field determines the URL of the endpoints to be generated.
The id
field determines the name to be used for the URL parameter (e.g. /users/:userID
).
Controllers are expected to be objects with create
, get
, getAll
, update
, and remove
methods, corresponding to basic CRUD operations.
Middleware methods can be inserted via the middleware
array. Middleware is applied to children of each routes - that is, if you have middleware to check for editing permission on one route, that middleware will also check for permissions on all requests to children of that route.
The children
array contains a list of other routes to be created under the original route.
Child routes do have one additional field in the data object: belongsTo
. This is used to identify a parent route's id
for use in the controller, since oftentimes routes describe relationships between models in a database (for example, all posts on a forum would belong to users based on the users' IDs).
const routes = [
{
path:'users',
id:'userID',
controller:<controller object goes here>,
middleware:[
<middleware objects go here>
],
children:[
{
path:'posts',
id:'postID',
controller:<controller object goes here>,
middleware:[
<middleware objects go here>
]
}
]
}
]
If we wished to simplify the route structure further, we could strip out unnecessary data (for example, if we had no middleware to apply).
const routes = [
{
path:'users',
id:'userID',
controller:<controller object goes here>
children:[
{
path:'posts',
id:'postID',
controller:<controller object goes here>
}
]
}
]
Based on this structure, we would have the following routes:
/users
/users/:userID
/users/:userID/posts
/users/:userID/posts/:postID
FAQs
A simple, lightweight routing solution for Express.
The npm package routesmith receives a total of 0 weekly downloads. As such, routesmith popularity was classified as not popular.
We found that routesmith 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.