For ex. I need to design an API with two features: payment validation and payment creation. I need both because the end user should know that everything is ok before actually confirm the payment creation. For creation I have
POST .../payment
with an input body. It returns HTTP 400 in case something went wrong.
The validation (or simulation) does the exact same process than the creation, stopping the process just before persisting the data. For this validation, is it better to have something like
Solution 1
GET .../is-payment-ok
also with an input body. It returns HTTP 200 including a boolean answer and some details.
Here the resource is not the payment, it's the information about the validity of the payment, which seems REST-compliant to me. The drawback being that the user of the API could be confused because if the payment is not valid, then the simulation would return HTTP 200 (with the boolean in the body set to false) while the creation would return HTTP 400.
, or
Solution 2
POST .../payment?simulation=true , or
POST .../payment-simulation
Here the HTTP response code would be exactly the same as for a payment creation. The drawback being that we use a POST, without actually 'posting' any resource.
How would you do it ? Is there a REST rule or common practice for this case ?