Kousha
Kousha

Reputation: 36219

RESTful implementation for "archiving" an entry

Say I have a table for machines, and one of the columns is called status. This can be either active, inactive, or discarded. A discarded machine is no longer useful and it only used for transaction purposes.

Assume now I want to discard a machine. Since this is an entry update, RESTfully, this would be a PUT request to /machines/:id. However, since this is a very special kind of an update, there could be other operations that would occur as well (for instance, remove any assigned users and what not).

So should this be more like a POST to /machines/:id/discard?

Upvotes: 1

Views: 478

Answers (3)

PressingOnAlways
PressingOnAlways

Reputation: 12356

From a strict REST perspective, have you considered implementing a PATCH? In this manner, you can have it update just that status field and then also tie it in to updating everything else that is necessary?

References:

https://www.mnot.net/blog/2012/09/05/patch http://jasonsirota.com/rest-partial-updates-use-post-put-or-patch

Upvotes: 1

vbranden
vbranden

Reputation: 5986

Personally I think post should be used when the resource Id is either unknown or not relevant to the update being made.

This would make put the method I would use especially since you have other status types that will also need to be updated

path

/machines/id

Message body

{"status":"discarded"}

Upvotes: 0

user8681
user8681

Reputation:

I think the most generic way would be to POST a Machine object with { status: 'discarded' } to /machines/:id/.

Personally, I'd prefer the /machines/:id/discard approach, though. It might not be exactly in accordance with the spec, but it's more clear and easier to filter. For example, some users might be allowed to update a machine but not "archive" it.

Upvotes: 0

Related Questions