I do not believe this post fully answers the question.
Situation
The problem
Sometimes duplicate resources are created and end up being referenced.
Solution
Expose an endpoint that allows resources to be "merged". This would do the following:
The Question
How would one do this restfully? I wanted to do something like:
PUT http://endpoint/resource/{id1}/merge/{id2}
{
//new merged resource
}
Where id1 =
the resource being kept and id2 =
the resource being. Alternatively this could be visa versa if it makes more sense.
However my concern is that the act of merging will update both resources on a PUT. Does this break the rules and is there a better, prescribed way to do this?
In my opinion, the RESTful paradigm is great for giving people guidelines on how your API probably behaves, but forcing everything you can into it doesn't result in a better developer experience.
I would much rather see well-documented POST actions for everything beyond the standard four verbs. Here's my vote:
POST http://endpoint/resources/{id1}/merge
{
"merge_id": {id2}
}
This also leaves you free to support a multi-id version, if that were commonplace.
POST http://endpoint/resources/{id1}/merge
{
"merge_ids": [
{id2}, {id3}, {id4}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With