Is creating REST subresources to get the last or f

2019-07-04 00:22发布

Let's say I have built a REST service for making notes that looks something like this:

GET    /notes/     // gives me all notes
GET    /notes/{id} // gives the note with the identified by {id}
POST   /notes/     // creates note
PUT    /notes/{id} // updates note identified by {id}
DELETE /notes/{id} // delete note

now I want to create subresources that allows me to get/update/delete the first or last note.

GET    /notes/first // get first note added
PUT    /notes/last  // updates last note added
DELETE /notes/first // delete first note

Does this go against the principles of REST?

Thank you in advance :)

EDIT:

PS: In this example i expect the ID to be always a number

1条回答
beautiful°
2楼-- · 2019-07-04 01:16

In my humble opinion this is perfectly legal and desirable. I especially like the semantics of DELETE /notes/first, but also consider POST /notes/first - put a new note before the first one.

In your case first and last are some sort of special magic identifiers or placeholders. On the other hand what are the alternatives?

查看更多
登录 后发表回答