DEV Community

technonotes-hacker
technonotes-hacker

Posted on

API - An overview

Application Programming Interface

  • Its like server/Waiter in a HOTEL refers to API. Image description
  • Interface--> Allow control of interaction with obstruction --> API is for Programmers.

Image description

  • Client & Server --> Can be any language.
  • All web application will have API.
  1. SOAP-API --> Simple Object Access Protocol --> Function/Method needs to be written so that one can call it . Its like a WRAPPER.
  2. REST-API --> REPRESENTATIONAL STATE TRANSFER --> If you know the concept of REST then everyone will write the same.

Image description

  • CURL ( cURL ) --> Command line CLIENT for testing and developing API.
  • Postman ( its a Graphical version based ) --> its a company now. 1 year we can use it for FREE.

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 & Body
  • Request Body can be sent via JSON Data types, which is default.
  • Response --> 200 OK or 404 Not found or 201 created along with Headers and body.
  • Layered --> It will have all configured LB & everything.

Image description

Why REST is popular ?

  1. Simple & Standardised --> Everyone will use the same method to use.
  2. Scalable & Stateles. Eg., It wont store anything. Each time it request as fresh request.
  3. High Performance & Caching.

CRUD

Image description

Continue with REST

Image description

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 Request

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 proper format or PrettyPrint

Image description

Image description

Post method

Image description

Image description

  • For this API , the best example is BANKING with website & Mobile APP. ( Why ? In internet banking you will pass all values and its the DB then gets the response which is obvious BUT think of the APP in your mobile which is lite weight app which will use API calls to DB and does the same operations )
  • Web Scraping --> you can get only DATA but you can't update or modify. Each website we need to write different web scraping code. EACH WEBSITE WILL HAVE DIFFERENT CONTROL.

  • ? & key = value & key = value

  • Now with KEY ,

Image description

Image description

Image description

Important Links

Important Notes

Reference

https://www.youtube.com/watch?v=HW9E4TYoYXU&list=PLiutOxBS1Mizte0ehfMrRKHSIQcCImwHL&index=38

** ACCEPT THE SLOWNESS **

Top comments (0)