What is a rest api?
When you search in Google and type in “dogs” and hit enter, you will get a list of results of “dogs”. You request “dogs” and the server responds with results of “dogs”. This is a simple way of explaining what a REST API is.
Each URL is a Request and the data sent back is called a Response.
Which stands for Application Programming Interface. It is rules that allow programs to communicate with each other. Developers create the APIs on the server to which the client can communicate with.
Which stands for Representational State Transfer. It is rules that the developers must follow when creating APIs.
A request consists of four elements:
- Data (Body)
Endpoints are the points of interaction between the API and the client. It is the URL that you request. The structure looks like this:
Root-endpoint is the starting point of the API. For example, Github’s API is https://api.github.com
The path determines where the resource actually is.
So for example: https://www.incloud.jp/products/athena
https://www.incloud.jp is the root-endpoint and /products/athena is the resource
There are 5 types of requests that you can send to the server.
These methods are used to perform four possible request actions: Create, Read, Update, and Delete.
Used to get a resource from the server. If the client performs a `GET` request, the server looks for the data that is requested and sends it back to the client. A GET request performs a READ operation. This is the default request method.
Used to create a new resource on the server. If the client performs a POST request, the server creates a new entry in the database and informs if it was successful or not. A POST request performs a CREATE operation.
PUT and PATCH
Used to update a resource on the server. A PUT or PATCH request performs an UPDATE operation.
Used to delete a resource from the server. A DELETE request performs a DELETE operation and the server deletes an entry in the database and tells you whether the deletion is successful.
Headers are used to provide information to both the client and server. It can be used for many purposes, such as authentication and providing information about the body content.
The Data (Body) contains information you want to be sent to the server. This can only be used with POST, PUT, PATCH or DELETE requests.
This is the basic explanation of REST APIs and it means to exchange object states between a server and a client. Understanding REST APIs is essential in building a successful web application. Let InCloud develop your REST APIs correctly to allow smooth exchange of information between the cloud and your clients.