Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use @Get('hello') instead of @GET and @Path('hello')? #49

Open
vellengs opened this issue Jun 13, 2018 · 3 comments
Open

Can I use @Get('hello') instead of @GET and @Path('hello')? #49

vellengs opened this issue Jun 13, 2018 · 3 comments

Comments

@vellengs
Copy link
Contributor

Can I use @get('hello') instead of @get and @path('hello').
That's simple and consistency with other framework.

@thiagobustamante
Copy link
Owner

Unfortunately no... But I like the ideia. We can add this feature in next release

@d0whc3r
Copy link
Contributor

d0whc3r commented Oct 12, 2018

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;
  }
}

@d0whc3r
Copy link
Contributor

d0whc3r commented Oct 12, 2018

I just submited a pull request #64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants