Rest API
API
The term API stands for Application programming interface. An API for a website is code that allows two software programs to communicate with each other.
API spells out the proper way for a developer to write a program requesting services from an operating system or other application.
REST
The term REST stands for Representational State Transfer. It is an architectural style that defines a set of rules in order to create Web Services. In a client-server communication, REST suggests to create an object of the data requested by the client and send the values of the object in response to the user.
REST + API
A RESTful API is an architectural style for an API that uses HTTP requests to access and use data. That data can be used to GET, PUT, POST and DELETE data types, which refers to the reading, updating, creating and deleting of operations concerning resources.
A RESTful API — also referred to as a RESTful web service or REST API — is based on representational state transfer (REST), which is an architectural style and approach to communications often used in web services development.
REST technology is generally preferred over other similar technologies. This tends to be the case because REST uses less bandwidth, making it more suitable for efficient internet usage. RESTful APIs can also be built with programming languages such as JavaScript or Python
Guiding Principles of REST
1. Client–server — By separating the user interface concerns from the data storage concerns, we improve the portability of the user interface across multiple platforms and improve scalability by simplifying the server components.
2. Stateless — Each request from client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server. Session state is therefore kept entirely on the client.
3. Cacheable — Cache constraints require that the data within a response to a request be implicitly or explicitly labeled as cacheable or non-cacheable. If a response is cacheable, then a client cache is given the right to reuse that response data for later, equivalent requests.
Uniform interface — By applying the software engineering principle of generality to the component interface, the overall system architecture is simplified and the visibility of interactions is improved. In order to obtain a uniform interface, multiple architectural constraints are needed to guide the behavior of components. REST is defined by four interface constraints: identification of resources; manipulation of resources through representations; self-descriptive messages; and, hypermedia as the engine of application state.
Layered system — The layered system style allows an architecture to be composed of hierarchical layers by constraining component behavior such that each component cannot “see” beyond the immediate layer with which they are interacting.
Code on demand (optional) — REST allows client functionality to be extended by downloading and executing code in the form of applets or scripts. This simplifies clients by reducing the number of features required to be pre-implemented.
Resources
A REST API will be made up of one or more resources. A resource is any information or content accessed at a given URL — resources could be JSON, images, HTML, or audio files. Resources can usually have one or more methods that can be performed on them over HTTP. Some of the most common are in the table below.
Methods Common Used
GET
Most often used to retrieve a resource at a given URL. Can be requested over and over without side effects. When your browser retrieves a web page, it is performing an HTTP GET request to retrieve that page and the assets on it.
POST
Most often used to create new data on a server. POST requests usually have side effects, like creating new comments or bank charges every time they are submitted.
PUT
Often used for updating data. You can submit a PUT request over and over and it should not have side effects (it should do the same thing every time).
DELETE
Used to delete resources from the server.
These HTTP verbs sometimes DO NOT map 1:1 to these tasks, but commonly REST APIs provide a “CRUD” interface to remote resources. “CRUD” stands for these four operations. Create, Read, update and Delete.