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.
route-methods
Advanced tools
route-methods
creates a list of routes and their methods from a nested
structure. This makes it easier to create nested APIs.
route-methods
was originally created to work with autoroute-base libraries
like autoroute-express-promise
.
Install with npm
:
npm install --save route-methods
enum method { get, post }
const normalRoute = {
route: '/yep/its/normal/:id',
methods: [
[ method.get, 'OK' ]
[ method.post, 'Posted' ]]
}
flattenRoute(normalRoute) // => [normalRoute]
const simpleRoute = {
'/dogs': [[
method.get, 'many dogs' ]],
}
flattenRoute(simpleRoute)
// =>
// [{
// route: '/dogs',
// methods: [[method.get, 'many dogs']]
// }]
const complexRoute = {
'/cats': {
_methods: [[
method.get, 'all cats' ]],
mine: [[
method.get, 'my cat',
method.post, 'a new cat' ]],
':id': [[
method.get, 'a special cat' ]]
}}
flattenRoute(complexRoute)
// =>
// [
// {route: '/cats', methods: [[method.get, 'all cats']]},
// {route: '/cats/mine', methods: [[ method.get, 'my cat', method.post, 'a new cat' ]]},
// {route: '/cats/:id', methods: [[ method.get, 'a special cat' ]]}
// ]
const newNestedRoute = {
'/hamsters': {
'/fish': [[
method.post, 'hamsters bite' ]]
}
}
flattenRoute(newNestedRoute)
// =>
// [{
// route: '/fish',
// methods: [[ method.post, 'hamsters bite' ]]}])
// })
import {subRoutes, flattenAltRoute, flattenRoute} from 'route-methods'
where RouteDefinition
is
interface RouteDefinition<T, S> {
/**
* Route name, e.g., route: "/api/myroute/:id"
*/
route: string
/**
* E.g., methods: [
* [method.get, req => myFunctionThatReturnsAPromiseGet(req.params["theIdName"])],
* [method.delete, req => myFunctionThatReturnsAPromiseDelete(req.params["theIdName"])]
* ]
*/
methods: [[T, S]]
}
subRoutes <T, S>(routes: [string, any]): RouteDefinition<T, S>[]
where routes
Tuple, [route, child routes and/or route methods]
flattenAltRoute <T, S>(nestedRoutes: any): RouteDefinition<T, S>[]
where nestedRoutes
has the form seen the examples. Can be a mixture of the
different examples.
flattenRoute <T, S>(routeDefinition: any): RouteDefinition<T, S>[]
where routeDefinition
can be the same argument in flattenAltRoute
or the
normalRoute
seen the examples.
FAQs
generate uniform list of routes and associated methods
The npm package route-methods receives a total of 2 weekly downloads. As such, route-methods popularity was classified as not popular.
We found that route-methods 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.