문제

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