I’m implementing a REST service in php.
q1. Can I split the controller and resource?
http://myserver/myCtrl.php?res=/items/1
q2. if not, is the standard specs (if any exists) for rewrites on iis, apache, nginx etc to survive the http-verb over the rewrite?
If not, how to solve?
For APIs (I have a framework for such) I tend to have a URL structure that looks as follows:
http://domain.com/api/%5Bresource]/[id]/[subresource]
I pass all requests to a front controller with a .htaccess file that parses incoming requests and passes the request off to the relavant controller. So my index.php looks similar to the following at the very simplest:
So if you call http://domain.com/api/news, then it will attempt to instantiate a class called
NewsController, and if it’s a GET request then theget()method of that class, orpost()for a POST request, and so on. The response of that call is then returned to the client as JSON.Hopefully that should be enough to get you started.