The difference between an API and a REST API


The difference between an API and a REST API

In: 198

REST is standardized architecture style for web based API.

API can be web based, but can also be local based, as example, windows api which allows you to execute actions on windows.

An API is just a formal, well-defined interface for programs to interact with each other. These interacting programs can be running on the same machine, or they can be communicating over a network. Doesn’t matter. The API just makes it possible to pass data back and forth in a structured manner.

A REST API is a certain type of API. It defines a set of standard rules as to how the computer hosting the API is supposed to behave, how it’s supposed to handle requests made to it, how you’re supposed to interact with it, how you’re supposed to access its data. The implementation details, that is how the API works under the hood, don’t matter. What a REST API is all about is how requests are responded to. It’s primarily used on servers where clients must be able to access, create or manipulate data.

An API is an “application programming interface” between two computer programs. It’s a rule that says “if you ask me a question like this, then I will do this thing and give you an answer like this”. If computer A agrees to this contract, then it is a service that “hosts the API” or “exposes the API”.

A REST API is a “Representational State Transfer API”. People realized quickly that a lot of APIs involve changing the “state” of data by the service hosting the API. Think creating an account, check the balance, updating a password, deleting an account. It became so common that Roy Fielding published a paper describing a new “style” of APIs called REST:

Today, REST APIs typically expose four “methods” to operate on each “entity” of data:

* GET – retrieve the entity
* POST – create a new entity
* PUT – update the entity
* DELETE – remove the entity

Any service that exposes these methods and implements them so that they do those operations is considered to be hosting a REST API.

API = A wall socket
RESTful API = Use a 3 pronged power plug, with the right prong being bigger than the left prong. None of that 2 pronged SOAP trash from the oughts.

Technically correct answer: a REST api is stateless, http-based and **returns hypertext**

Real-life answer: a REST api is http-based, probably stateless, and almost certainly **doesn’t** return hypertext

More info here: [](