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

Support for multiple paths on the same mapping #1422

Closed
mageddo opened this issue Mar 24, 2019 · 8 comments
Closed

Support for multiple paths on the same mapping #1422

mageddo opened this issue Mar 24, 2019 · 8 comments
Assignees
Labels
status: pr submitted A pull request has been submitted for the issue type: enhancement New feature or request
Milestone

Comments

@mageddo
Copy link

mageddo commented Mar 24, 2019

Expected Behaviour

I think it would be very nice if @Get, @Post, etc. have the support for multiple paths instead of only one, something like that

@Get({"/api/v1.0/settings", "/api/v2.0/settings"})
public String getSettings(){
.....
}

Actual Behaviour

I can't map multiple paths to the same controller method, so I have to create a common controller method and create another method for every new mapping I want to create, it is a LOT more verbose to develop

@Get("/api/v1.0/settings")
public String v1GetSettings(){
    return commonGetSettings();
}

@Get("/api/v2.0/settings")
public String v2GetSettings(){
    return commonGetSettings();
}

String commonGetSettings(){
....
}

Environment Information

  • Operating System: not applicable
  • Micronaut Version: 1.1.0.BUILD-SNAPSHOT
  • JDK Version: not applicable
@mageddo
Copy link
Author

mageddo commented Mar 24, 2019

Looking at the router reference I've created the following example which make a hack for my case, anyway I think this is a nice freature which should be considered

@Patch(value = "/api/v{version:[12]}.0/settings")
public HttpResponse route(String version, @Body Object o){
.......

@jameskleeh
Copy link
Contributor

which make a hack for my case

I don't think that is a hack. That is the intended use case

@mageddo
Copy link
Author

mageddo commented Mar 24, 2019

For my case yes, but thinking in a case where you have two totally different URIs but you want to call the same method then I think the first example fits better, something like

@Get({"/legacy-url/my-project", "/new-web-site/the-new-project"})
public String loadProject(){
.....
}

Just like Spring Web do

@graemerocher
Copy link
Contributor

I think what would make sense here is to allow the HTTP annotations to be repeatable. The example above looks complex to me

@jameskleeh
Copy link
Contributor

jameskleeh commented Mar 24, 2019 via email

@graemerocher graemerocher added the type: enhancement New feature or request label Mar 25, 2019
@graemerocher graemerocher added this to the 1.2.0 milestone Mar 25, 2019
@recursivecodes
Copy link
Contributor

I think what would make sense here is to allow the HTTP annotations to be repeatable. The example above looks complex to me

I think that would be very nice, but would make it even better (to me) is to allow stacking methods.

Example:

@Get("/foo")
@Post("/foo")
String method(HttpRequest request) { 
    if ( request.method == 'GET' ) {}
    if ( request.method == 'POST') {}
    ...
}

@graemerocher graemerocher removed this from the 1.2.0 milestone Jun 5, 2019
@jameskleeh jameskleeh added this to the 1.3.0 milestone Aug 1, 2019
@jameskleeh jameskleeh self-assigned this Sep 10, 2019
@jameskleeh jameskleeh added status: pr submitted A pull request has been submitted for the issue and removed status: in progress labels Oct 1, 2019
@saw303
Copy link
Contributor

saw303 commented Oct 15, 2019

@graemerocher why did you close this ticket? Is it fixed or won't it be fixed? I'm asking because I don't see any reference to a PR or commit.

@graemerocher
Copy link
Contributor

Oops sorry. PR merged #2188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pr submitted A pull request has been submitted for the issue type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants