Hi Bruno,
on one hand, you define a "route" which binds all uris such as
"/users/{user}/birthday" to a new instance of the BirthdayResource
class.
On the other hand, the resource is in charge to perform the request,
that is to say return a representation (if any) in case of "GET"
requests, delete the resource in case of "DELETE" request, etc. The
resource knows what happens and what to do.
In your case, the birthday resource is responsible to get the user (if
any), and return a representation of the user's birthday only if the
user exists. For example:
1- the BirthdayResource constructor looks for the user and store it
as an attribute
2- the "getRepresentation(Variant)" method returns a representation
only if the user attribute is not null
I hope this will help you.
Do you expose a lot of attributes such as "birthday"?
best regards,
Thierry Boileau
> Hello,
> I'd like to model resources using Restlet in a similar way as Section 12
> of the tutorial ("Reaching target Resources"). As a simple example, I'd
> like to map URIs like "/users/{user}/birthday" to read the full name of
> a user from a database (or hash-table).
>
> As far as I understand the tutorial, I can create a Resource class (for
> example BirthdayResource) that reads the username from the attribute in
> the constructor and reads the birthday from the database. Then, it can
> attach it to the router using something like this:
> router.attach("/users/{user}/birthday", BirthdayResource.class);
> The problem is that some username values might not be in this database,
> in which case I'd like to return a "NOT FOUND" response.
>
> Where is the right place to look whether-or-not the resource actually
> exists? Shouldn't this be done before the Resource instance is created?
> Where does this fit in the router/attach model?
>
> Best wishes,
>
> Bruno.
>