API request with Python

What is API ?

Application Programming Interface (API) is an application interface that allows two applications to communicate each other. Creating API is creating routes(endpoint and parameter) and response back some data. Means that other application can use our service with requesting API. RESTFul (Representational state transfer) is style or rules of creating APIs.

Example of API and HTTP request, response

For example, there is application A and application B. Application A wants weather forecast data to show user the weather data in application. Application B have weather data and create some routes(api routes) to allow other application to use weather data(services). Then application A request application B (creating HTTP request) and application B response back requested weather data to application A. Then application A can use data to show user the weather data in application.

API requests

request method ➜ get (request.get)

url ➜ https://jsonplaceholder.typicode.com/posts

import requestsresponse=requests.get("https://jsonplaceholder.typicode.com/posts")response_data = response.json()print(response_data)

Endpoint and parameters

documentation

request user with Sincere@april.biz email from jsonplaceholder

https://jsonplaceholder.typicode.com/users?email=Sincere@april.biz

simple request

import requestsresponse=requests.get("https://jsonplaceholder.typicode.com/users?email=Sincere@april.biz")response_data = response.json()print(response_data)

Using params argument

Endpoint ➜ https://jsonplaceholder.typicode.com/users

parameters ➜ email=Sincere@april.biz

import requestsresponse=requests.get("https://jsonplaceholder.typicode.com/users", params={"email":"Sincere@april.biz"})response_data = response.json()print(response_data)

--

--

--

Learning javascript and web-development

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

No Such Method Exception in Java

Mastering AWS Amplify’s SMS Flows in Flutter — Part 3: Sign Up Flow

What is Amazon CloudWatch?

Starting up with Amazon Alexa Skill Development

What is Virtualization and What are its Types?

Jobs to be done: JTBD WT*?

What are Low-Code Development Platforms?

What is V2V? How to select the V2V migration tool?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cho Zin Thet

Cho Zin Thet

Learning javascript and web-development

More from Medium

Creating a django app in 5 mins!

How to: pgAdmin with Open ID Connect in Docker-Compose

Creating a basic REST API using Flask

Full Installation Guide of MySQL 8.0 on Ubuntu Machine