Question

I'm using Restlet library and I would like to know if it is possible to call a specific method of a class when accessing through a URL.

Right now I have something like this:

public Restlet createInboundRoot() {
    Router router = new Router(getContext());  

    router.attach("/monitor", Monitor.class);
}

Which calls the Monitor class when accessing to /monitor/ by URL. I would like to be able to do things like this:

public Restlet createInboundRoot() {
    Router router = new Router(getContext());      

    router.attach("/monitor/name", Monitor.getName());
    router.attach("/monitor/description", Monitor.getDescription());
}

Is this possible with Restlet framework? Right now the workaround I found was by using GET parameters and using conditions on the represent method:

public StringRepresentation represent() {
    String type= getQuery().getValues("type");

    if(type.equals("getName")){
        this.getName();
    }
    if(type.equals("getDescription")){
        this.getDescription();
    }    
}

But it doesn't sound like the way to do it.

Was it helpful?

Solution

Your solution is the best way to validate REST guidelines.
So, unless you convert name and description to be resources leave it this way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top