Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between REST and API?

Tags:

rest

I want to know the main difference between REST and API. Sometimes I see REST API in programming documents, then is REST or API same as REST API? I would like to know more about relation between REST, API and REST API.

like image 359
Nomura Nori Avatar asked Dec 16 '16 17:12

Nomura Nori


People also ask

What is difference between REST and Web API?

As Web APIs are lightweight architecture, they are designed for gadgets constrained to devices like smartphones. In contrast, REST APIs send and receive data over systems making it a complex architecture.

Is REST an API?

Representational State Transfer (REST) is a software architecture that imposes conditions on how an API should work. REST was initially created as a guideline to manage communication on a complex network like the internet.

What is difference between Java API and REST API?

Correct, the Java API is internal, your code that uses that would be running inside a server. REST is the external interface. It is provided by internal code though, so there's some commonality there.

What is REST API and why REST API?

REST API stands for REpresentational State Transfer API. It is an API that follows a set of rules for an application and services to communicate with each other. REST API abides by the following rules: Statelessness: Systems aligning with the REST paradigm are bound to become stateless.


2 Answers

REST is a type of API. Not all APIs are REST, but all REST services are APIs.

API is a very broad term. Generally it's how one piece of code talks to another. In web development API often refers to the way in which we retrieve information from an online service. The API documentation will give you a list of URLs, query parameters and other information on how to make a request from the API, and inform you what sort of response will be given for each query.

REST is a set of rules/standards/guidelines for how to build a web API. Since there are many ways to do so, having an agreed upon system of structuring an API saves time in making decisions when building one, and saves time in understanding how to use one.

Other popular API paradigms include SOAP and GraphQL.

Note that the above attempts to answer the question in regards to how the terms are commonly used in web development. Roman Vottner has offered a different answer below which offers good insights into the original definition of the term REST with more technical precision than I have provided here.

like image 90
dave Avatar answered Sep 18 '22 19:09

dave


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 22
Tukaram Patil Pune Avatar answered Sep 16 '22 19:09

Tukaram Patil Pune