So I’ve currently made an controller that extends AbstractRestfulController, which allows me to call different class methods depending on the HTTP method. I have used curl to call these methods, for example:
curl -i -H “Accept: application/json” -X DELETE rest.dev/index/1
which calls the delete() method in my index controller.
However, I want my users to be able to make these calls within the web browser.
Now let’s say a user has signed in to the website and want to delete a database entry by clicking a button, would it make sense to make a DELETE call? But I can’t use DELETE method in html form, only POST, so how exactly would I make this call? It seems like the usual approach is to use AJAX, but if I want a site that works without JS enabled, it seems like curl is my best option. So the way I see it is that I need to make a form with POST and then use curl to relay the $_POST data to my DELETE method I use in curl. It seems a bit weird to me, and I wonder if there’s any better approach.
REST is the wrong approach if you want to provide services for a human-controlled html webbrowser like firefox or chrome. maybe you will can add a special flag for these routes within your POST requests and translate them to use your REST services.
REST is certainly a proper approach for your API. Using curl is a server-side method to call on external URL resources, which can also be REST endpoints.
As for communicating with a REST API from the browser, it is correct that you can only use the POST method in normal HTML, however with AJAX (using Javascript), you can use all the HTTP verbs you’d like too. Take the jQuery AJAX library for instance. With a simple “type” or “method” variable, you can set the proper HTTP method.