Note that there are some explanatory texts on larger screens.

plurals
  1. POREST API - why use PUT DELETE POST GET?
    text
    copied!<p>So, I was looking through some articles on creating REST API's. And some of them suggest using all types of HTTP requests: like <code>PUT</code> <code>DELETE</code> <code>POST</code> <code>GET</code>. We would create for example <em>index.php</em> and write API this way:</p> <pre><code>$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; } </code></pre> <p>OK, granted - I don't know much about web services (yet). But, wouldn't it be easier to just accept <em>JSON</em> object through regular <code>POST</code> or <code>GET</code> (that would contain method name and all parameters) and then respond in JSON as well. We can easily serialize/deserialize via PHP's <code>json_encode()</code> and <code>json_decode()</code> and do whatever we want with that data without having to deal with different HTTP request methods.</p> <p>Am I missing something?</p> <p><strong>UPDATE 1:</strong></p> <p>Ok - after digging through various API's and learning a lot about <em>XML-RPC</em>, <em>JSON-RPC</em>, <em>SOAP</em>, <em>REST</em> 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 <a href="https://stackapps.com/questions/2/getting-started-with-the-api">Stack Exchange API</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload