What is the difference between REST and API?

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

Thank you

+21
source share
4 answers

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

API is a very broad term. Actually, how one piece of code speaks to another. In web development, an API often refers to how we get information from an online service. The API documentation will provide you with a list of URLs, request parameters and other information on how to make a request from the API, and will tell you what response will be given for each request.

REST is a set of rules / standards / guidelines for creating a web API. Since there are many ways to do this, having a consistent API structuring system saves time when making decisions when creating it and saves time on understanding how to use it.

+38
source

REST basically just refers to the use of the HTTP protocol as it was intended. Use the HTTP GET method for the URL to retrieve information, possibly in different formats based on Accept HTTP headers. Use the HTTP POST method to create new elements on the server, PUT to edit existing elements, DELETE to delete them. Make an idempotent API, i.e. Repeating the same query with the same information should give the same result. Organize your URLs hierarchically, etc.

REST is simply the guiding principle for using URLs and the HTTP protocol to structure the API. It says nothing about return formats, which could also be JSON.

This contradicts, for example, APIs sending binary or XML messages to a designated port without using differences in HTTP methods or URLs in general.

+14
source

There is no comparison in REST and API, REST is an API type.

An API is typically a set of protocols deployed in application software to communicate with other software components (such as browser interactions with servers) and provide an interface for the services that application software offers to multiple existing consumers.

And Rest is a form of principle that the API follows, in which the server provides information no matter what the client wants to interact with the services.

+3
source

REST is a web architecture style that controls the behavior of clients and servers. While the API is a more general set of protocols that is deployed on top of the software to help it interact with some other software. REST is for web applications only. And mainly deals with HTTP requests and responses. This makes it practically applicable in any programming language and is easily tested.

0
source

Source: https://habr.com/ru/post/1013227/


All Articles