jQuery in Action, 2nd edition*
The moose likes Web Services and the fly likes which is more restful ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "which is more restful ?" Watch "which is more restful ?" New topic
Author

which is more restful ?

Lmn Opq
Greenhorn

Joined: Jun 19, 2011
Posts: 5
I am using the restlet framework. I have a resource called Person. This person has the following fields :

- name
- age
- job

a person could be either a teacher, a programmer, or a doctor.
According to the job type, the person will have a set of properties. For example, if a person is a teacher, he will have the following properties :

- teaching hours
- subjects
- classes

if a person is a programmer, he would have the following properties :

- skills
- experience

the question is, when I want to post a new person, should I post the person(name,age,job) to the following url :

/myapplication/Persons

and then post the properties to one of the following ( according to his job )

/myapplication/Persons/{id}/teacher
/myapplication/Persons/{id}/doctor
/myapplication/Persons/{id}/programmer

or should I post all the information to the url :

/myapplication/Persons
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Personally, I would choose the latter approach since a teacher, a doctor and a programmer are all persons and should be treated in the same manner as such.
I would consider adding a "role" property to the base Person resource. Depending on what the clients accessing the service want for kind of data, I would also consider adding a Teachers, a Doctors and a Programmers resources. Adding these resources would also make it possible to create a Person by POSTING to, for instance, the Teachers resource.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: which is more restful ?