简体   繁体   中英

Rest api - adding tags to an entity

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM