質問

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.

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top