{"id":20011358,"url":"https://github.com/mvillarrealb/lite-router","last_synced_at":"2026-04-12T03:32:22.980Z","repository":{"id":65460824,"uuid":"145355222","full_name":"mvillarrealb/lite-router","owner":"mvillarrealb","description":"Simple and flexible router publisher for express and restify","archived":false,"fork":false,"pushed_at":"2018-08-20T02:36:40.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-13T03:21:59.255Z","etag":null,"topics":["api-router","expressjs","nodejs","rest-api","restifyjs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mvillarrealb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-20T02:17:04.000Z","updated_at":"2018-09-24T01:40:53.000Z","dependencies_parsed_at":"2023-01-24T18:17:40.098Z","dependency_job_id":null,"html_url":"https://github.com/mvillarrealb/lite-router","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"cdf1d08bc83330d729848e71fc9151c616650725"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvillarrealb%2Flite-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvillarrealb%2Flite-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvillarrealb%2Flite-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvillarrealb%2Flite-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mvillarrealb","download_url":"https://codeload.github.com/mvillarrealb/lite-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241447645,"owners_count":19964336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-router","expressjs","nodejs","rest-api","restifyjs"],"created_at":"2024-11-13T07:25:33.088Z","updated_at":"2025-12-31T01:05:40.612Z","avatar_url":"https://github.com/mvillarrealb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-lite-router\r\n\r\nSimple and flexible router publisher for express and restify\r\n\r\n# Installation\r\n\r\n```bash\r\n    npm install --save node-node-lite-router\r\n```\r\n\r\n# Usage\r\n\r\n## Choosing an Implementation\r\n\r\nnode-lite-router has a two main implementations to be chosen: **restify** and **express**, booth of them share the same api.\r\n\r\n### Restify\r\n\r\nTo use LiteRouter in restify\r\n\r\n```javascript\r\n\r\nconst LiteRouter = require(\"node-lite-router\").restify;\r\nconst routesDefinition = require(\"./path_to/routes_definition.js\");\r\n\r\nlet routerHandler = LiteRouter.init({\r\n    controllers: controllers,\r\n    middlewares: middlewares\r\n});\r\n\r\nrouterHandler.publishRoutes(routesDefinition).then((router) =\u003e {\r\n    //do something with the created router\r\n});\r\n```\r\n---\r\n\r\n### Express\r\n\r\nTo use LiteRouter in express\r\n\r\n```javascript\r\n\r\nconst LiteRouter = require(\"node-lite-router\").express;\r\nconst routesDefinition = require(\"./path_to/routes_definition.js\");\r\n\r\nlet routerHandler = LiteRouter.init({\r\n    controllers: controllers,\r\n    middlewares: middlewares\r\n});\r\n\r\nrouterHandler.publishRoutes(routesDefinition).then((router) =\u003e {\r\n    //do something with the created router\r\n});\r\n```\r\n\r\nNote that in booth cases LiteRouter.init method takes two parameters: *controllers* and *middlewares*, these can be an array of modules(loaded via mod-loader for example) or a string pointing to a directory.\r\n\r\nIf you specify a directory name, then liteRouter will execute **require** on the specified path so you may want to use bootstraping for controllers and middlewares.\r\n\r\n---\r\n\r\n## Route Definition\r\n\r\nIn order to use node-lite-router you have to use a route definition; a json array used to create a router with the following syntax:\r\n\r\n```json\r\n[\r\n    {\r\n        \"httpVerb\":\"get\",\r\n        \"route\":\"/tasks\",\r\n        \"action\":\"TasksController?findAll\",\r\n        \"middlewares\": [\r\n            \"visitCounter\"\r\n        ]\r\n    }\r\n]\r\n```\r\nIt also can be expressed as a javascript module\r\n\r\n```javascript\r\nmodule.exports = [\r\n    {\r\n        httpVerb:\"get\",\r\n        route:\"/tasks\",\r\n        action:\"TasksController?findAll\",\r\n        middlewares: [\r\n            \"visitCounter\",\r\n            (req,res,next)=\u003e {\r\n                console.log(\"Hi there just passing by\")\r\n                next()\r\n            }\r\n        ]\r\n    }\r\n]\r\n```\r\n\r\nThe following table show the parameters required to configure a route definition\r\n\r\nfield|description|Example\r\n-|-|-\r\nhttpVerb|Http verb to be published in the route|get\r\nroute|Endpoint to be published|/tasks\r\naction|ControllerName?actionName to be executed|TaskController?findAll\r\nmiddlewares|List of middlewares|[ \"visitCounter\" ]\r\n\r\n\r\n## actionString syntax\r\n\r\nAs you may noticed the action parameter follows a syntax like **taskController?findAll**, this is a syntax I've decided to call *actionString* is a simple way of representing class and method invocation, LiteRouter knows that you are specifying a class?method binding to a route. \r\n\r\nThe same goes for middlewares if you specify a middleware as a string it will look for them in the middlewares object, however if LiteRouter detects actionString syntax it will try to resolve your middleware as a method from a class.\r\n\r\nIn this example we define a update action with the verb PUT for a route identified for /tasks/:task_id in the middlewares you can see two entries:\r\n\r\n* visitCounter: A simple middleware that is going to bee looked up into middlewares object.\r\n* TasksController?exists: An actionString specifying that TasksController has a method called exists that will be threated as a middleware for the execution stack.\r\n\r\n```javascript\r\nmodule.exports = [\r\n    {\r\n        httpVerb:\"put\",\r\n        route:\"/tasks/:task_id\",\r\n        action:\"TasksController?update\",\r\n        middlewares: [\r\n            \"visitCounter\",\r\n            \"TasksController?exists\"\r\n        ]\r\n    }\r\n]\r\n```\r\nFor this example the TasksController will look like this:\r\n\r\n```javascript\r\n\r\nclass TasksController {\r\n    update(req,res) {\r\n        //update logic\r\n        res.send({..})\r\n    }\r\n\r\n    exits(req,res,next) {\r\n        if(exits...) {\r\n            return next()\r\n        } else {\r\n            return res.status(404).send(...)\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n# Running Examples\r\n\r\nTo have a clear idea of how node-lite-router works you have two examples for running apis with express and restify.\r\n\r\n---\r\n\r\n# Testing\r\n\r\n```bash\r\n    npm test\r\n```\r\n# Generating docs\r\n\r\n```bash\r\n    npm generate-docs\r\n```\r\n---\r\n\r\n# Why node-lite-router\r\n\r\nnode-lite-router allows you to encapsulate route publishing and middleware organizing as externalized files, this enable a modular development with a fine separation of concerns for your express \u0026 restify REST Apis.\r\n\r\n# Notes\r\n\r\nSomebody has the name lite-router in the npm registry :D","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvillarrealb%2Flite-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmvillarrealb%2Flite-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvillarrealb%2Flite-router/lists"}