开发者

RESTLet 2.0.9 - query regarding multiple @Get and @Post annotations?

I am new to RESTLet and using 2.0.9. What I want to do is have multiple methods with @Get & @POST annotation. I have access to the VO classes (value objects) and so I don't need to use JSON or XML representation. I have used the excellent tutorial available at http://wiki.restlet.org/docs_2.0/13-restlet/21-restlet/318-restlet/303-restlet.html#dsy303-restlet_jse. I have designed the following classes:

User - VO POJO with attributes for an User. UserResource inteface:

public interface UserResource 
{ 
    @Get 
    public User 开发者_如何学运维userLogin();    
 }

For single @Get annotation, the client code works fine.

     ClientResource cr = new ClientResource(url); 
     // Get the Contact object 
     UserResource resource = cr.wrap(UserResource.class); 
     User user = resource.userLogin();*

Now, I want to use multiple methods with @Get annotation. For e.g., have two/three flavors of getUser objects similar to what we have in normal DAO layer in single JVM.

User getUser(int userId) 
User getUser(String domain, String username) 
boolean isUserNew(int userid)* 

and similar multiple methods to update and add users [@POST annotation]:

int addUser(User user) 
int updateUser(int userId, User user)

Is it possible to achieve some thing like this ? If not what are the alternative ? Where can I get documentation for Annotations @Get, @Post ?


I think the way this is meant to be done is having:

  • UsersResource with a @Get annotated method that fecthes a user by it's unique id;
  • UsersDomainUsernameResource (similar fetch logic...)

@Get methods will then handle various cases:

for example:

  • myserverside.com/users/100
  • myserverside.com/users/domain/username

when it comes to your example boolean isUserNew(int userid) it is not a REST operation. Keep in mind REST only means basic CRUD operations. I think you'd just have to get the user's representation and then perform whatever check you need (isNew... isBlonde...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜