Rest api - 向实体添加标签 [英] Rest api - adding tags to an entity
问题描述
我正在设计一个 rest api,我需要在其中向实体添加标签.实体是使用 POST/content
创建的,其中 json 数据在请求正文中传递.我想允许在发出 POST
请求时添加标签,稍后也允许添加标签.这就是我所拥有的.
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>
推荐答案
简短回答:你会这样做吗
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
这将创建一个实体并返回一个实体 ID,例如 29292
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
要删除标签,您只需
DELETE /entity/29292/tags
长答案:您想学习本指南来创建具有更多细节和最佳功能的宁静 api实践.
Long answer: you want to study this guideline on creating restful apis that has a lot more details and best practices.
这篇关于Rest api - 向实体添加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!