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(){
.....
}
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(){
....
}
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){
.......
which make a hack for my case
I don't think that is a hack. That is the intended use case
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
I think what would make sense here is to allow the HTTP annotations to be repeatable. The example above looks complex to me
Probably something for 1.2
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 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.
Oops sorry. PR merged https://github.com/micronaut-projects/micronaut-core/pull/2188
Most helpful comment
I think what would make sense here is to allow the HTTP annotations to be repeatable. The example above looks complex to me