Basics of REST API
API stands for Application programming interface. In simple words it is used to communicate with 2 different software's.
These software’s may be written or may not be written in same programming languages. That means say one software written in python and one software written in Java Script.
Lets the software written in python is server software and the software written in JavaScript is client software.
The client software sends request to the server and the server process the request and give response to the client
In previous implementations the response would be in XML format.But at present times the response would in JSON format.
The JSON format would like below:
Its simply a list of dictionaries.
We will communicate with the two softwares using the internet in REST architecture style. So the name comes REST API.
Question: Why do we need API’s at first place?
Ans: Some of them would get a doubt why do we need API’s , we can simply write front end logic and access the data from database.
The answer is security.
Consider a scenario you are user in one of the website. The website can is directly connected to the database. Now with slight modification in the script we can get the details of other person.
The other reason is versatility. Now a days all web services can be accessible via android phone, IOS phone and many other softwares. So we don’t write server code for each and every other programming language using REST API
It can also be used in automating the tasks
Some of the API’s are available to the public which don’t require any authentication. while some are private which requires authentication. The authentication protocol is OAuth 2.0
Python code to explain the API’s
import requests
import json
response = requests.get("https://serpapi.com/search.json?q=McDonald%27s&location=austin%2C+texas%2C+united+states&tbm=lcl&api_key=secretkey")
print(response.json())
The secret key will be getting from the website.
When we execute the api with the given API then following output is shown