REST API-向实体添加标签 [英] Rest api - adding tags to an entity

查看:95
本文介绍了REST API-向实体添加标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆