routing-controllers-multiparam
A simple plugin for routing-controller which allows to inject param from multiple sources.
Installation
Module installation
npm install routing-controllers-multiparam --save
(or the short way with NPM v5):
npm i routing-controllers-multiparam
Peer dependencies
This package is only a simple plugin, so you have to install the routing-controllers
package because it can't work without them.
Usage
The usage of this module is very simple. All you need is:
;// import the `@MultiParam` decorator and `ParamType` enum from the module; // declare the controller class using routing-controller decorators@ @ return role ; // start the server;
And that's it! This will lead to inject the first non-undefined value from the list of sources, so when you specify roleBody
param in body but not roleQuery
inside path (query string) it will be injected. It works just like switch-case!
API reference
Function signatures
The @MultiParam
decorator has two overloads:
: ParameterDecorator;
: ParameterDecorator;
Parameters and types
NamedParamOptions
- a type of object that propertyallow
can be a dictionary of allowed types:
;};
So the usage is just like in the example:
@
UnamedParamOptions
- a type of object that propertyallow
can beParamType
or array ofParamType
;
It 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:
@
More info
If you need more examples of usage, go to the sources and check unit tests file - /src/decorators/MultiParam.ts
. If you have questions or new features/ideas, feel free to open an issue on GitHub repository.
Release notes
0.1.0
- initial version with basic
@MultiParam
decorator support