In Restlet, what's the difference between a Restlet class and a Resource class?
문제
I've gone through the firstResource bit of the Restlet 1.1 tutorial and put together a web service that handles GET, POST, DELETE, PUT by subclassing the Resource
class and overriding the appropriate methods and using a Router
to attach the subclassed Resource
classes.
So I'm left thinking - what's the point of a Restlet
?
I can attach a
Resource
or aRestlet
to anApplication
Router
A
Resource
has methods to handle HTTP GET POST etc.A
Restlet
has ahandle
method - do I somehow forward that on to aResource
class?
What's the difference? When do I use one or the other? What would I put in a Restlet
handle
method?
Thanks.
해결책
Restlet
is the base class for various restlet server facilities, among them Application
and Router
. When its handle()
method is called it's supposed to interpret the request, dispatch it to a suitable child restlet or query the matching resource (the GET/POST/... handle methods), and put the result back in the response.
So, restlets and resources are nodes of a tree. Resources are the leafs of that tree.
Restlets usually don't answer to request but delegate them down the tree. Resources actually reply.
In general, you will program only custom resources and use pre-defined restlets.