Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 701
Shaolin Avatar asked May 15 '12 05:05

Shaolin


People also ask

What is the difference between REST API and normal API?

The primary goal of API is to standardize data exchange between web services. Depending on the type of API, the choice of protocol changes. On the other hand, REST API is an architectural style for building web services that interact via an HTTP protocol.

What is the output of a REST API?

The default output format for the REST API is in a human readable and navigable html format.

What are the outputs for an API?

The API Output tool outputs a maximum of 255 characters per row, and the data from each field is contained within double-quotes. If a string value contains double-quotes, each quote is replaced by 2 consecutive quotes. Blob fields display the size of the blob, for example, "14 Bytes".

What is the difference between REST and open API?

The most common open API architectures fall into two categories: REST APIs and SOAP APIs. SOAP and REST offer different methods to invoke a web service. SOAP-based APIs typically use XML as a data exchange format, while RESTful APIs typically use JSON back and forth. Both approaches have supporters and opponents.


2 Answers

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.

like image 123
GordonM Avatar answered Oct 13 '22 21:10

GordonM


REST mostly just refers to using the HTTP protocol the way it was intended. Use the GET HTTP method on a URL to retrieve information, possibly in different formats based on HTTP Accept headers. Use the POST HTTP method to create new items on the server, PUT to edit existing items, DELETE to delete them. Make the API idempotent, i.e. repeating the same query with the same information should yield the same result. Structure your URLs in a hierarchical manner etc.

REST just is a guiding principle how to use URLs and the HTTP protocol to structure an API. It says nothing about return formats, which may just as well be JSON.

That is opposed to, for example, APIs that send binary or XML messages to a designated port, not using differences in HTTP methods or URLs at all.

like image 32
deceze Avatar answered Oct 13 '22 22:10

deceze