I have an existing REST application on my server.
For example, if you send a request with the DELETE method to “/users/3” it will delete the user whose id is 3.
But now I would like to create an HTML “client” for this application. For example there is an HTML form, and when you submit it the user is deleted.
Unfortunately you can’t write <form method="delete" action"/users/3"> because only GET and POST are supported by forms. And even if you could, I would like the user to be redirected to a “the operation successed” or a “there was an error” page afterwards, which would not be possible.
I considered using AJAX, but I need to support the [insert injurous comment here] people who deactivated Javascript
I could modify the application so I can send POST requests with method=DELETE&redirect=/successpage&redirectfail=/failpage but that would take a lot of time.
Is there a way to send the POST request to a PHP page, which would in turn translate it to the real request, then would interpret the status code returned by my app, and do the appropriate redirection?
Thank you
EDIT: I’m not using any framework for the app. This was a very simple app at the beginning, and it became more complex over time
This can be done using a CURL request to your REST API:
See the
CURLOPT_CUSTOMREQUESToption:For example:
So this would be actioned in the target file of the form after the form has been POSTed onto it.