{"id":20604820,"url":"https://github.com/themost-framework/router","last_synced_at":"2025-03-06T16:53:11.072Z","repository":{"id":177793983,"uuid":"648054066","full_name":"themost-framework/router","owner":"themost-framework","description":"A router service for implementing advanced MVC features","archived":false,"fork":false,"pushed_at":"2023-08-06T07:16:43.000Z","size":144,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-17T07:36:08.027Z","etag":null,"topics":["actions","api","controllers","express-js","middleware","rest","restful-api","router"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/themost-framework.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-01T05:34:41.000Z","updated_at":"2023-07-19T18:01:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"d92afa5d-9e5e-4478-8b39-9b7cc53f8f51","html_url":"https://github.com/themost-framework/router","commit_stats":null,"previous_names":["themost-framework/router"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themost-framework%2Frouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themost-framework%2Frouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themost-framework%2Frouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/themost-framework%2Frouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/themost-framework","download_url":"https://codeload.github.com/themost-framework/router/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242250870,"owners_count":20096895,"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":["actions","api","controllers","express-js","middleware","rest","restful-api","router"],"created_at":"2024-11-16T09:24:57.365Z","updated_at":"2025-03-06T16:53:11.049Z","avatar_url":"https://github.com/themost-framework.png","language":"TypeScript","readme":"[![npm](https://img.shields.io/npm/v/@themost%2Frouter.svg)](https://www.npmjs.com/package/@themost%2Frouter)\n![Dependency status for latest release](https://img.shields.io/librariesio/release/npm/@themost/router)\n![GitHub top language](https://img.shields.io/github/languages/top/themost-framework/router)\n[![License](https://img.shields.io/npm/l/@themost/router)](https://github.com/themost-framework/themost/blob/master/LICENSE)\n![GitHub last commit](https://img.shields.io/github/last-commit/themost-framework/router)\n![GitHub Release Date](https://img.shields.io/github/release-date/themost-framework/router)\n[![npm](https://img.shields.io/npm/dw/@themost/router)](https://www.npmjs.com/package/@themost%2Frouter)\n\n![MOST Web Framework Logo](https://github.com/themost-framework/common/raw/master/docs/img/themost_framework_v3_128.png)\n\n# @themost/router\nRouter service for express.js\n\n## Install\n\n    npm i @themost/router\n\n## Usage\n\n`RouterService` service provides a different approach for handling requests by using\ncontrollers. A controller is an instance of `HttpController` class which uses [javascript decorators](https://github.com/tc39/proposal-decorators) for defining extra attributes in both\nclasses and methods. \n\n    import { HttpController, httpController, httpGet } from '@themost/router';\n    \n    @httpController()\n    export class IndexController extends BaseController {\n\n        @httpGet()\n        index() {\n            return this.json({\n                message: 'Hello World!'\n            });\n        }\n\n    }\n\n`IndexController` is marked by `@httpController` class decorator and `IndexController.index()` by `@httpGet` method decorator.\n\nCreate an instance of `HttpApplication` class and register `controllerRouter` express.js middleware:\n\n    const app = express();\n    app.use(express.json());\n    ...\n    const httpApp = new HttpApplication();\n    const routes = [\n        {\n            path: '',\n            action: 'index',\n            controller: IndexController\n        },\n        ...\n    ];\n    httpApp.getService(RouterService).addRange(...routes);\n    app.use(controllerRouter(httpApp));\n\n## @httpController()\n\nAnnotates a class which is going to be used as controller\n\n## @httpGet(name,params)\n\nA method decorator which defines an HTTP GET method\n\n\u003e name: string\n\nA string which represents the name of the method while executing HTTP requests. This name is being used by routing service while parsing routes which contain `:action` param:\n\n    {\n        path: 'home',\n        controller: HelloController,\n        children: [\n            {\n                path: '',\n                redirectTo: 'index'\n            },\n            {\n                path: ':action'\n            }\n        ]\n    }\n\n\u003e params : HttpParamAttributeOptions[]\n\nAn array of objects which represents a collection of route or querystring params\n\n    @httpGet({\n        params: [\n            {\n                name: 'id',\n                type: 'Integer',\n                required: true\n            }\n        ]\n    })\n    getItem(id) {\n        //\n    }\n\n ## @httpPost(name,params)\n\nA method decorator which defines an HTTP POST method\n\n    @httpPost({\n        name: 'reply',\n        params: [\n            {\n                name: 'message',\n                type: 'Text',\n                maxLength: 512\n            }\n        ]\n    })\n    reply(message) {\n        //\n    }\n\n## @httpPut(name,params)\n\nA method decorator which defines an HTTP PUT method\n\n\u003e name: string\n\nA string which represents the name of the method while executing HTTP requests. This name is being used by routing service while parsing routes which contain `:action` param:\n\n\u003e params : HttpParamAttributeOptions[]\n\n    // e.g. PUT /api/items\n\n    @httpPut({\n        params: [\n            {\n                name: 'item',\n                fromBody: true,\n                required: true\n            }\n        ]\n    })\n    update(item) {\n        //\n    }\n\nAn array of objects which represents a collection of route or querystring params\n\n## @httpDelete(name,params)\n\nA method decorator which defines an HTTP DELETE method\n\n\u003e name: string\n\nA string which represents the name of the method while executing HTTP requests. This name is being used by routing service while parsing routes which contain `:action` param:\n\n\u003e params : HttpParamAttributeOptions[]\n\nAn array of objects which represents a collection of route or querystring params\n\n    // e.g. DELETE /api/items/:id\n\n    @httpDelete({\n        params: [\n            {\n                name: 'id',\n                required: true\n            }\n        ]\n    })\n    remove(id) {\n        // remove item by id\n    }\n\n## @httpPatch(name,params)\n\nA method decorator which defines an HTTP PATCH method\n\n## @httpHead(name,params)\n\nA method decorator which defines an HTTP HEAD method\n\n## @httpOptions(name,params)\n\nA method decorator which defines an HTTP OPTIONS method\n\n## @httpActionConsumer(HttpConsumer | ConsumerFunction)\n\nA method decorator which defines an operation that is going to be executed before processing controller action.\n\n    // GET /api/home/messages\n\n    @httpGet({\n        name: 'messages'\n    })\n    @httpActionConsumer(async (context) =\u003e {\n        const username = (context.user \u0026\u0026 context.user.name) || 'anonymous';\n        if (username === 'anonymous') {\n            throw new AccessDeniedError();\n        }\n    })\n    getMessages() {\n        return [\n            {\n                message: 'Hello World'\n            }\n        ];\n    }    \n\ne.g. a consumer which validates if `context.user` is empty and throws access denied error.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthemost-framework%2Frouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthemost-framework%2Frouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthemost-framework%2Frouter/lists"}