Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST "dry-run" option for PUT or POST

Tags:

rest

Is there an idiomatic way of achieving this:

I need to PUT/POST a given entity. However, before actually putting it I need to do some changes on a more volatile system, and if that works I will go on.

So I will first ask if the PUT/POST is acceptable and then later actually do the PUT/POST.

I've thought of just using a "dry-run" query-parameter, but it doesn't feel like the right way.

Update: Trying to clarify my problem. The point is that the first PUT is just for verification of the entity.

Me           System A       Volatile System X
|    Dry PUT    |                    :
|-------------->|                    :
|               |                    :
|   20x / 40x   |                    :
|<--------------|                    :
|               :                    :
| Upon PUT OK do some related work   :
|----------------------------------->|
|               :                    |
| Work completely                    |
|<-----------------------------------|
|               :
|PUT (for real) :
|-------------->|
|               |
|     20x       |
|<--------------|
like image 959
thoredge Avatar asked Apr 04 '13 14:04

thoredge


1 Answers

Logically I feel that this could perhaps be solved by a some kind of state property. If you are using JSON, you might for example consider adding a property like this:

{
  "draft" : true
}

The first time you do the PUT request, you mark the item as draft. It stores the item but doesn't do anything else with it .

After your server accepted your request, you can then do your 'related work' elsewhere, and if that succeeded as well you can submit another PUT request to the same resource, this time setting draft to false.

like image 144
Evert Avatar answered Sep 20 '22 19:09

Evert