1

Given two resources

  • http://example.com/places/1
  • http://example.com/places/2

How should the endpoint look like to merge both resources into a single resource? Ideally after the merge only 1 resource will remain.

At first glance I could do a PUT to http://example.com/places/1 with params[:src_id] = 2. Which would merge the attributes from the second resource into the first and delete the the second resource. Does anyone else have a better approach?

Note that I'm using Rails which doesn't support the http MERGE verb so that's out of the question.

1
  • Looking at github.com/rails/rails/commit/… Rails does seem to support MERGE since 2010. Not sure when it made it into a release though. Also not sure if it would be appropriate to adapt it from webdav context to non-webdav. Commented May 10, 2013 at 12:19

1 Answer 1

2

I suggest a new controller PlacesMergeController with a new and create action. In the new action, you would have a form asking which places to merge. The form will do a POST request to the create action, where you do the actual merging. Depending on the complexity of the logic you could also have a PlacesMerge model (non-AR!).

This approach should give you maximum flexibility in terms of handling source/target of the merge operation - and it's easily maintainable.

Sign up to request clarification or add additional context in comments.

1 Comment

+1: Merging feels like a POST to me given that a dedicated verb is unavailable.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.