Search code examples
javarestlet

Restlet routing with query string


I have a resource that currently is routed like this:

router.attach("/{version}/content/{language}", ContentResource.class);

I want to add to this resource a query string that will look something like this:

router.attach("/{version}/content/{language}?segment={segment}", ContentResource.class);

The thing is, that when I try to get to the resource with the routing, I fail to get into it.

Can someone explain why and how to solve it?


Solution

  • You don't have to specify query parameters at the route definition level. If you want to use a query parameter named segment, here is the way to do:

    • Route definition

      router.attach("/{version}/content/{language}", ContentResource.class);
      
    • Get query parameter value

      public class ContentResource extends ServerResource {
          String value = getQueryValue("segment");
          (...)
      }
      

    Hope it helps you, Thierry