tags:

views:

26

answers:

1

Hello,

This is probably a really stupid/simple question with such an obvious answer that it seems not worth stating in restlet documentation. Where and how (if at all) can Restlet pass parameters to methods in ServerResource classes?

Given this class:

public class FooServerResource extends ServerResource {
    @Get
    public String foo(String f) {
        return f;
    }
}

and a Router attachment router.attach("/foo", FooServerResource.class);

I know that if I use a Restlet client connector I could create a proxy for this class and invoke methods directly, but what if I am making calls to this ServerResource from some other non-java language, e.g. PHP?

+1  A: 

You can access the query parameters using from the resource reference. Typically, something like this:

@Get
public String foo() {
    Form queryParams = getReference().getQueryAsForm();
    String f = queryParams.getFirstValue("f");
    return f;
}

Generally speaking (and this would work for other methods that GET), you can access whatever is passed to the request (including the entity, when appropriate) using getRequest() within the ServerResource.

Bruno
Ok, how does one pass an entity fo the request then?
Finbarr
Are you talking from the client's point of view?
Bruno
If you're talking about passing an entity as part of the request, then this can only be done with POST, not GET. The entity is the POST content body.
Qwerky