REST API - why use PUT DELETE POST GET?
- by Andre
So -i was looking through some articles on creating REST API's.
And some of them suggest using all types of HTTP requests: like PUT DELETE POST GET.
So - we would create for example index.php and write API this way:
$method = $_SERVER['REQUEST_METHOD'];
$request = split("/", substr(@$_SERVER['PATH_INFO'], 1));
switch ($method) {
case 'PUT':
....some put action....
break;
case 'POST':
....some post action....
break;
case 'GET':
....some get action....
break;
case 'DELETE':
....some delete action....
break;
}
Ok - granted - I don't know much baout web services (yet).
But - wouldn't it be easier to just accept JSON object through normal $_POST and then respond in JSON as well. We can easily serialize/deserialize via php's json_encode and json_decode and do whatever we want with that data without having to deal with different HTTP request methods...
Am I missing something?
UPDATE 1:
Ok - after digging through various API's and learning a lot about XML-RPC, JSON-RPC, SOAP, REST I came to a conclusion that this type of API is sound. Actually stack exchange is pretty much using this approach on their sites and I do think that these people know what they are doing Stack Exchange API.