I am developing a REST service, and one of my server-side operations manipulates the DB in a way that may take a while, but once the operation has started, the DB cannot be recovered (this is a constraint that comes from the system we are using on our server. I might be able to change it in later versions, but for now we are stuck with this constraint). The result is that I need an "ok/cancel" dialog with a warning, before allowing the operation to run.
At first I wanted to put the logic of creating the dialog on the client-side, but that seems to violate HATEOAS (for example, if I do change the framework on my server side, the dialog won't be needed, but I won't want to change the client if my API stays the same). My next solution was returning a response with the warning, and an ok that links to a different POST operation, but I am unsure on when to send my parameters. Do I send the parameters in the first POST? If so, how do they get to the second POST (without holding application state, of course)? Sending the parameters only to the second POST isn't an option since only HATEOAS will determine if the second one is needed.
I have found a similar question here: REST, HTTP DELETE and parameters But this has 2 problems:
I would be happy to hear your thoughts on the matter.
P.S: This is my first post on stackoverflow.com (after years of using it to find answers for questions that were asked before me), so please forgive me if the format of the question isn't quite right (you are welcome to correct me, of course).
Any REST request includes four essential parts: an HTTP method, an endpoint, headers, and a body. An HTTP method describes what is to be done with a resource.
Enter a Request BodyAs part of a POST, PUT, or PATCH request, a data payload can be sent to the server in the body of the request. When you select one of those methods from the method drop-down button, the API Connector form changes to display an input field for the request body.
To post JSON to a REST API endpoint, you must send an HTTP POST request to the REST API server and provide JSON data in the body of the POST message. You also need to specify the data type in the body of the POST message using the Content-Type: application/json request header.
One of your server-side operations needs confirmation before it can be executed. The way I see it this means two different calls, which may for example mean to first check that you need the confirmation and then doing the actual action.
For example, you may request that the client first does a GET to see if a confirmation is required and retrieve the message to display, then do the actual POST with the action. If you don't have a GET request first, the POST may return a 4xx (maybe 412?) error.
BUT, keep in mind that no matter what you do, you need cooperation from the client. Even if the server does receive a GET request, the client may receive the response, not show the confirmation and doing the post anyway, it's not something you can solve 100% server side.
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