{"id":17932724,"url":"https://github.com/michallytek/routing-controllers-multiparam","last_synced_at":"2025-08-23T16:08:50.400Z","repository":{"id":66211870,"uuid":"106102449","full_name":"MichalLytek/routing-controllers-multiparam","owner":"MichalLytek","description":"A simple plugin for routing-controllers which allows to inject param from multiple sources.","archived":false,"fork":false,"pushed_at":"2017-10-10T08:32:39.000Z","size":34,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-15T16:45:23.246Z","etag":null,"topics":["decorator","express","koa","nodejs","routing-controllers","typescript","typescript-library"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MichalLytek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2017-10-07T14:03:17.000Z","updated_at":"2022-03-14T15:34:10.000Z","dependencies_parsed_at":"2023-02-21T23:15:59.032Z","dependency_job_id":null,"html_url":"https://github.com/MichalLytek/routing-controllers-multiparam","commit_stats":null,"previous_names":["19majkel94/routing-controllers-multiparam"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/MichalLytek/routing-controllers-multiparam","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichalLytek%2Frouting-controllers-multiparam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichalLytek%2Frouting-controllers-multiparam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichalLytek%2Frouting-controllers-multiparam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichalLytek%2Frouting-controllers-multiparam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MichalLytek","download_url":"https://codeload.github.com/MichalLytek/routing-controllers-multiparam/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichalLytek%2Frouting-controllers-multiparam/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271755437,"owners_count":24815407,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["decorator","express","koa","nodejs","routing-controllers","typescript","typescript-library"],"created_at":"2024-10-28T21:30:09.585Z","updated_at":"2025-08-23T16:08:50.371Z","avatar_url":"https://github.com/MichalLytek.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# routing-controllers-multiparam\n\n[![npm version](https://badge.fury.io/js/routing-controllers-multiparam.svg)](https://badge.fury.io/js/routing-controllers-multiparam)\n[![Dependency Status](https://david-dm.org/19majkel94/routing-controllers-multiparam.svg)](https://david-dm.org/19majkel94/routing-controllers-multiparam)\n[![devDependency Status](https://david-dm.org/19majkel94/routing-controllers-multiparam/dev-status.svg)](https://david-dm.org/19majkel94/routing-controllers-multiparam#info=devDependencies)\n[![peerDependency Status](https://david-dm.org/19majkel94/routing-controllers-multiparam/peer-status.svg)](https://david-dm.org/19majkel94/routing-controllers-multiparam#info=devDependencies)\n\nA simple plugin for [routing-controllers](https://github.com/pleerock/routing-controllers) which allows to inject param from multiple sources.\n\n## Installation\n\n#### Module installation\n\n`npm install routing-controllers-multiparam --save`\n\n(or the short way with NPM v5):\n\n`npm i routing-controllers-multiparam`\n\n#### Peer dependencies\n\nThis package is only a plugin, so you have to install the `routing-controllers` package because it can't work without it.\n\n## Usage\n\nThe usage of this module is very simple. All you need is:\n\n```ts\nimport { JsonController, Post, createExpressServer } from \"routing-controllers\";\n// import the `@MultiParam` decorator and `ParamType` enum from the module\nimport { MultiParam, ParamType } from \"routing-controllers-multiparam\";\n\n// declare the controller class using routing-controllers decorators\n@JsonController()\nclass ProductsController {\n    // example use case:\n    // register action on two routes and get `categoryId` param from query or path so both routes will work\n    @Get(\"/products\")\n    @Get(\"/categories/:categoryId/products\")\n    getProductsByCategory(\n        // use the `@MultiParam` decorator to define the sources of the param to inject\n        @MultiParam(\"categoryId\", { required: true, allow: [ParamType.QueryParam, ParamType.Param] })\n        categoryId: string,\n    ) {\n        return {\n            categoryId,\n        };\n    }\n}\n\n// start the server\ncreateExpressServer({ controllers: [SampleController] }).listen(3000);\n\n```\nAnd that's it! This will lead to inject the first non-undefined value from the list of sources, so when you specify `categoryId` param in path but not as a query string, it will be injected. It works just like switch-case - finds first source that exist.\n\n## API reference\n\n#### Function signatures\n\nThe `@MultiParam` decorator has two overloads:\n\n```ts\nexport function MultiParam(options: NamedParamOptions): ParameterDecorator;\n```\n\n```ts\nexport function MultiParam(paramName: string, options: UnamedParamOptions): ParameterDecorator;\n```\n\n#### Parameters and types\n\n- `NamedParamOptions` - a type of object that property `allow` can be a dictionary of allowed types:\n```ts\n{\n    required?: boolean;\n    allow: { \n        [P in ParamType]?: string | string[];\n    };\n};\n```\nSo the usage is just like this:\n```ts\n@MultiParam({ allow: {\n    [ParamType.QueryParam]: [\"api_key\", \"apiKey\"],\n    [ParamType.HeaderParam]: \"X-Auth-Api-Key\",\n}})\n```\n\n- `UnamedParamOptions` - a type of object that property `allow` can be `ParamType` or array of `ParamType`\n```ts\n{\n    required?: boolean;\n    allow: ParamType | ParamType[];\n};\n```\nIt can be used only with `paramName` parameter when you want to get the param from multiple source but which is avaible on the same name:\n```ts\n@MultiParam(\"apiKey\", { allow: [ParamType.QueryParam, ParamType.HeaderParam] })\n```\n\n## Known limitation/issues\n\n* param normalization doesn't work - number params aren't casted from string (TBD after routing-controller `0.8.x` release)\n* there's no validation and transforming options (only primitives are supported)\n\n## More info\n\nIf you need more examples of usage, go to the sources and check unit tests file (`/src/decorators/MultiParam.spec.ts`).\nIf you have questions or new features/ideas, feel free to open an issue on GitHub repository.\n\n## Release notes\n\n**0.1.0**\n\n* initial version with basic `@MultiParam` decorator support\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichallytek%2Frouting-controllers-multiparam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichallytek%2Frouting-controllers-multiparam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichallytek%2Frouting-controllers-multiparam/lists"}