Hi,
I'm using restlet version 1.0.10 (stable) and I'm basing my implementation
on the firstResource tutorial at
http://www.restlet.org/documentation/1.0/firstResource
Q1: I would like to know how to support URIs like:
/items?name={name}&description={desc}
i.e. what should I replace the "URI Template matching query variables"
String within:
router.attach("URI Template matching query variables",
ItemsAlgoResource.class);
Currently, I have the following inside firstApplication.java
@Override
public synchronized Restlet createRoot() {
// Create a router Restlet that defines routes.
Router router = new Router(getContext());
// Defines a route for the resource "list of items"
router.attach("/items", ItemsResource.class)
// Defines a route for the resource "item"
router.attach("/items/{itemName}", ItemResource.class);
// Defines a route for the resource "list of items" but returning only
items that match
router.attach("URI Template to support
/items?name={name}&description={desc}", ItemResourceQueryVariables.class);
return router;
}
Q2: I would also like to know how to extract the query variables inside my
Resource implementation ItemResourceQueryVariables.java
I've looked at the tutorial part05 [1] for some clues and [2],
but I don't what lines of code can be use to do something like this inside
constructor of ItemResourceQueryVariables.java:
/** The sequence of characters that identifies the resource. */
String itemName;
String itemDescription;
public ItemResourceQueryVariables(Context context, Request request,
Response response) {
super(context, request, response);
// Get the "itemName" attribute value taken from the URI template
this.itemName = //a line of code the get the
value of "name" from the URI /items?name={name}&description={desc}
this.itemDescription = //a line of code the get the value
of "description" from the URI /items?name={name}&description={desc}
}
Q3: I would also like to know how to support arbitrary number of URI query
variables.
i.e. How do I modify the following bit of code below, so that I can support
/items?name={name}&description={desc} and /items?name={name}
Currently, I have the following inside firstApplication.java:
@Override
public synchronized Restlet createRoot() {
// Create a router Restlet that defines routes.
Router router = new Router(getContext());
// Defines a route for the resource "list of items" but returning only
items that match
router.attach("URI Template to support
/items?name={name}&description={desc} AND /items?name={name} ",
ItemsQueryResource.class);
return router;
}
[1] http://www.restlet.org/documentation/1.0/tutorial#part05
[2] http://restlet.tigris.org/servlets/ReadMsg?listName=discuss&msgNo=4887
--
Thanks and kind regards,
Dennis Lo