问题
I am designing a rest api in which I need to add tags to an entity. The entity is created using POST /content
where the json data is passed in the request body. I want to allow adding tags while the POST
request is being made, and also later on. This is what I have.
POST /content?tag=foo&tag=bar
PUT /content/{id}?tag=baz&tag=bat
Now, how do I allow deleting tags? What would be a better approach>
回答1:
Short answer: is you would do it like this
Assuming your entity is the content in your to create an entity you would:
POST /entity
This will create an entity and return an entity id, for example 29292
if you need to add tags on an entity you would go down the hierarchy like this:
POST /entity/29292/tags
to delete tags you would simply
DELETE /entity/29292/tags
Long answer: you want to study this guideline on creating restful apis that has a lot more details and best practices.
来源:https://stackoverflow.com/questions/14822383/rest-api-adding-tags-to-an-entity