For APIs (I have a basis for this), I tend to have a URL structure that looks like this:
http://domain.com/api/[resource 022/[ID.BIZ/[subresource]
I pass all requests to the front controller with a .htaccess file that parses incoming requests and passes the request to the relavant controller. So my index.php looks something like this:
<?php $request = explode('/', trim($_SERVER['REQUEST_URI'], '/')); $resource_name = ucfirst($request[0]).'Controller'; $http_verb = strtolower($_SERVER['REQUEST_METHOD']); $controller = new $resource_name; $response = call_user_func_array(array($controller, $http_verb), array($request)); header('Content-Type: application/json'); echo json_encode($response);
So, if you call http://domain.com/api/news , then it will try to instantiate a class called NewsController , and if it is GET then get() request for a method of this class or post() for a POST request, etc. . The response of this call is then returned to the client as JSON.
Hope this should be enough for you to get started.
source share