close
close

API – An Overview

API – An Overview

Application programming interface

  • It’s like server/waitress/waitresses in a HOTEL, which refers to API.
    Image description
  • Interface–> Allows control over interaction with obstruction –> API is for programmers.

Image description

  • Client & Server –> Can be any language.
  • All web applications have an API.
  1. SOAP API –> Simple Object Access Protocol –> Function/Method must be written so that one can call it. It is like a WRAPPER.
  2. REST API –> REPRESENTATIVE STATE TRANSFER –> If you know the concept of REST, everyone will write the same thing.

Image description

  • CURL ( cURL ) –> Command line CLIENT for API testing and development.
  • Postman (based on the graphical version) –> it’s a company now. We can use it for FREE for 1 year.

Continue with REST

  • Method (GET, POST, PUT/PATCH, DELETE)
  • Address / Endpoint (URL)
  • Path

Image description

  • Query/Search Parameters –> Starts with ? followed by KEY & VALUE.
  • Authorization
  • Header and body text
  • The request body can be sent using JSON data types, which is standard.
  • Answer –> 200 OK or 404 Not Found or 201 created together with headers and body.
  • Layered –> All LB and everything is configured.

Image description

Why is REST popular?

  1. Simple and standardized –> Everyone uses the same method.
  2. Scalable and stateless. For example, it doesn’t store anything. Every time it makes a new request.
  3. High performance and caching.

ROUGH

Image description

Continue with REST

  • https://api.github.com/users/
  • users –> this will usually be plural, followed by SINGULAR –> username.
  • https://jsonplaceholder.typicode.com/todos

Image description

  • https://jsonplaceholder.typicode.com/todos/1

Image description

import requests

api_url = "https://jsonplaceholder.typicode.com/todos/1"

response = requests.get(api_url)

print(response)

response.json()

print(response.json())

All requests

import requests

api_url = "https://jsonplaceholder.typicode.com/todos/"

response = requests.get(api_url)

print(response)

response.json()

print(response.json())

Image description

Print in the right size or PrettyPrint

Image description

Image description

Postal method

Image description

Image description

  • For this API the best example is BANKING with website & mobile APP. (Why? In interest banking you pass all the values ​​and DB gets the answer, which is obvious, BUT think about the APP on your mobile, that is a lightweight app that uses API calls to DB and performs the same operations)
  • Web scraping –> you can only get DATA but you can not update or change. Every website has to write different web scraping code. EVERY WEBSITE HAS DIFFERENT CONTROL.

  • ? & key = value & key = value

  • Now with KEY,

Image description

Image description

Important links

  • https://realpython.com/api-integration-in-python/
  • https://jsonplaceholder.typicode.com/ –> API playground.

  • Free open API for weather –> https://open-meteo.com/ –> curl “https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41¤t=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m”
  • https://tamilpesu.us/en/number/ –> https://tamilpesu.us/en/number/

  • https://www.slideshare.net/slideshow/an-introduction-to-rest-api/76492672
  • https://speakerdeck.com/cli4d/introduction-to-rest-apis
  • https://www.slideshare.net/slideshow/what-is-rest-api-rest-api-concepts-and-examples-edureka/174179563
  • https://jiminbyun.medium.com/building-python-scripts-for-rest-api-calls-a-practical-guide-2-9-3ac9ca1d701a
  • https://github.com/vinta/awesome-python ( Important site )

Important notes

  • ”’ … ”’ –> Comment multiple lines.
  • pprint –> it is like creating JSON beautification, for this we need to use “import pprint”.
  • curl -X GET https://jsonplaceholder.typicode.com/todos/1
  • curl -X POST -d {“userID”:101} https://jsonplaceholder.typicode.com/posts
  • What is BROWSER Automation for Sites?
  • Try this and get the output –> https://www.instructables.com/Get-Weather-Data-Using-Python-and-Openweather-API/
  • All social media platforms offer their services through API.
  • Also try this –> http://tamilpesu.us/number/34?type=IN –> website –> https://tamilpesu.us/en/number/
  • POSTMAN –> good platform with user interface, widely used.
  • https://en.wikipedia.org/api/rest_v1/ –> wikipedia rest-api

  • md –> Markdown
  • Example of a supermarket 🙂 You have to search everything, otherwise we can’t find it right away. https://github.com/vinta/awesome-python –> this is as many codes, so search them one by one.

Reference

** ACCEPT THE SLOWNESS **