github linkedin
Routes with dynamic parameters in Micronaut

If you want to create a REST controller in Micronaut, which accepts a dynamic amount of parameters, e.g.

curl http://localhost:8080/?foo=1&bar=2&baz=3

where the stuff after the ? is varying, here’s the way to go:

class FooController {
    public void takeAll(@Nullable @QueryValue("values") Map<String, String> values) {
        System.out.println("Received: " + values);

Micronaut will map the query parameters to the values map. When running the curl from above, the map contains [foo: 1, bar: 2, baz: 3].

If you need a typesafe client for this, that’s how you do it:

public interface FooClient {
    void takeAll(@Nullable @QueryValue("values") Map<String, String> values);

Tags: java micronaut

Back to posts