REST modeling with hierarchy

How can you model hierarchy resources? Suppose, for example, that a person has a “bulletin board” and that “message” is a resource. Let's say that a “message” can have answers so that it forms a discussion thread. How to model the concept of flow?

Does this “message” include children? Is a "stream" a resource? Finally, which REST URI will work in this case?

+3
source share
2 answers

If you think that all responses to the message are also messages, I would give an identifier to each of them and use these URIs:

#message {id}  (only the message, no replies)
/messages/{id}

#replies to the {id} message (a list of the id of the replies)
/messages/{id}/replies

To create a new message, make a message in uri

 /messages

To create a response to the message {id}, make a message in

/messages/{id}/replies

. , Restful.

uri, {}.

GET {messages} → uris , {message1}, {message2} ..

GET {message1} → message1, , xml :

<message responses="{link to message1 responses}">
    <date>...</date>
    <body>...</body>
</message>

{ 1} - , , uris .

, ,

<message responses="{link to message1 responses}" inResponseTo="{uri}" >
    <date>...</date>
    <body>...</body>
</message>

, , {messages} uri. , ( , , uri).

- , PUT uri.

uris , .

+1

RESTful . REST . , /threads/, URI , URI URI .. URI , .

+1

All Articles