Rest api - adding tags to an entity

允我心安 提交于 2019-12-13 07:03:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!