Difference between an Output of a normal API and a REST API

Shaolin picture Shaolin · May 15, 2012 · Viewed 15.7k times · Source

What is the difference between a REST API and a normal API (which prints a JSON response)?

Answer

GordonM picture GordonM · May 15, 2012

There is no difference at all. REST describes a way of interacting with a HTTP server, not what the server should return in response. Most web apps interact with the server side by POST or GET requests with any additional information needed to fulfil the request in a form submission for POST or the query string for GET. So if you want to delete something from the server they typically do POST with a form that contains data that specifies a resource along with an instruction to delete it.

However, HTTP implements methods (also known as verbs) other than GET or POST. It also implements, amongst others, HEAD (return the same headers you would have done for a GET, but with no response body), PUT (Take the request body and store its content at whatever URL the PUT request was made to), and DELETE (Delete whatever resource exists at the specified URL). A REST interface simply makes use of these additional verbs to convay the meaning of the request to the server.

Browsers typically only support GET and POST for "normal" (non-XHR) requests, but tools like Curl can issue the full set of HTTP verbs. You can also use additional verbs with XHR-based techniques such as AJAX.

You will still have to provide a traditional non-REST API for browsers to use, unless you're making javascript and XHR support a requirement for using your app.