Object – Oriented Programming in Python-1
Object – Oriented Programming in Python-1
• What is API ?
• What is Web API?
• Advantages of using a Web API.
• Requests Library(requests library).
• Git and GitHub Repositories.
What is API?
• API – (Application Programming interface)
• API is a set of protocols , routines, and tools for building software and applications.
• It specifies how software components should interact and API’s allow
communication b/w different systems or platforms.
• API acts as an intermediary between two systems.
API Key:
• API Key acts as a secret code that identifies the calling program and grants access
to the API’s data and functionality.
• The use of API key helps to ensure that the API is used only by authorized clients
and helps to maintain the security and integrity of the data and services provided
by the API.
Requests Library(requests):
• It is a python library used to send http requests.
• It is designed to provide a simple and intuitive interface for making http requests.
• The basic use of requests involves sending an http requests to specified URL , and
processing the response that is received from the server.
• This process can be done by using requests. get method for making GET requests,
or the requests.post method for making POST requests.
• commands to install requests library pip install requests.
• Ex: https://api.genderize.io offers an API that determines the gender, to utilize the
API, the name is passed as a parameter in the url.
URL : https://api.genderize.io/?name=Chandhana
URL : https://api.apilayer.com/fixer/convert?
to={to_currency}&from={from_currency}&amount={amount}&apikey={api_ke
y}
• The API then returns the results in JSON format, including information such as the
name, gender and a probability score.
• An example of the API’s response, When the name “Chandhana ” is passed.
• Response : {"count":26,"name":"chandhana","gender":"female","probability":0.54}
This program uses web API to find the gender based on name.
import requests