typescript-rest
typescript-rest copied to clipboard
Can I use @Get('hello') instead of @GET and @Path('hello')?
Can I use @Get('hello') instead of @GET and @Path('hello'). That's simple and consistency with other framework.
Unfortunately no... But I like the ideia. We can add this feature in next release
In decorators.ts
Could be as simple as:
export function GETMapping(path: string) {
return function (...args: any[]) {
args = _.without(args, undefined);
if (args.length === 3 && typeof args[2] === 'object') {
processHttpVerb(args[0], args[1], HttpMethod.GET);
return PathMethodDecorator.apply(this, [args[0], args[1], args[2], path]);
}
throw new Error('Invalid @GETMapping Decorator declaration.');
};
}
It only works for method decorator.
Before:
@Path('/hello')
export class HelloController {
/**
* Send a greeting message.
* @param name The name that will receive our greeting message
*/
@GET
@Path(':name')
sayHello(@PathParam('name') name: string): string {
return 'Hello ' + name;
}
}
After:
@Path('/hello')
export class HelloController {
/**
* Send a greeting message.
* @param name The name that will receive our greeting message
*/
@GETMapping(':name')
sayHello(@PathParam('name') name: string): string {
return 'Hello ' + name;
}
}
I just submited a pull request https://github.com/thiagobustamante/typescript-rest/pull/64