Skip to content

Micronaut @Controller wildcard #4184

Answered by ilopmar
ghost asked this question in Q&A
Sep 25, 2020 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

You can put there any arbitrary variable:

@Controller("/foo/{something}/api/v1")
public class HelloController {

    @Get("/data")
    public String data1() {
        return "data1";
    }

    @Get("/data2")
    public String data2() {
        return "data2";
    }
}

This will match:

ivan@nobita:~$ curl localhost:8080/foo/A/api/v1/data
data1

ivan@nobita:~$ curl localhost:8080/foo/B/api/v1/data
data1

ivan@nobita:~$ curl localhost:8080/foo/A/api/v1/data2
data2

ivan@nobita:~$ curl localhost:8080/foo/B/api/v1/data2
data2                                            

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ghost
Comment options

Answer selected by ilopmar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant