Purpose: RESTful API
Question: Is there a method that I have below the true RESTful API, or is it missing something like what I was told?
This is a three-part question.
Suppose I have a PHP project that has an API that returns data in XML or JSON formats, you will get access to the API, as described below.
server.com/article/123 | Returns ID 123 using GET
server.com/article/new | Creates a new article using POST
server.com/article/123/edit | Edits an article with the ID 123 using POST
server.com/article/123/delete | Deletes article with ID 123 using POST
1)
I always read that it PUTshould be used to edit objects, below I put the word POST, since the user sends POSTURIs to tht for the delete action, should I use PUTphp on using something similar instead?
$_PUT = array();
if($_SERVER['REQUEST_METHOD'] == 'PUT') {
parse_str(file_get_contents('php://input'), $_PUT);
}
2)
, SO , RESTful API, , ...
In short, your service is not RESTful, but it is close. Rather than specify actions (edit, delete, ...) in URL segments, you will want to make use of HTTP verbs (GET, PUT, POST, DELETE).
, , , API, , NOT RESTful?
RESTful API, , , ?
3)
, JSON - ...
<?php
header('HTTP/1.1 200 OK');
header('Content-type: application/json');
$data =
echo json_encode($data);
?>
- ?
, , .