Application Programming Interface
- Its like server/Waiter in a HOTEL refers to API.
- Interface--> Allow control of interaction with obstruction --> API is for Programmers.
- Client & Server --> Can be any language.
- All web application will have API.
- SOAP-API --> Simple Object Access Protocol --> Function/Method needs to be written so that one can call it . Its like a WRAPPER.
- REST-API --> REPRESENTATIONAL STATE TRANSFER --> If you know the concept of REST then everyone will write the same.
- 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
- 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.
Why REST is popular ?
- Simple & Standardised --> Everyone will use the same method to use.
- Scalable & Stateles. Eg., It wont store anything. Each time it request as fresh request.
- High Performance & Caching.
CRUD
Continue with REST
- https://api.github.com/users/
- users --> it will be mostly plural , followed by SINGULAR --> username.
- https://jsonplaceholder.typicode.com/todos
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())
Print in proper format or PrettyPrint
Post method
- 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 ,
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
- ''' ... ''' --> Commenting multiple lines.
- pprint --> its like making 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 platform expose their service with API.
- Try this also --> http://tamilpesu.us/number/34?type=IN --> website --> https://tamilpesu.us/en/number/
- POSTMAN --> good platform with UI, mostly used.
- https://en.wikipedia.org/api/rest_v1/ --> wikiepedia rest api
- md --> Markdown
- Super Market Example :-) You need to search each and everything, we wont get it immediately. https://github.com/vinta/awesome-python --> this as many codes , so search one by one.
Reference
https://www.youtube.com/watch?v=HW9E4TYoYXU&list=PLiutOxBS1Mizte0ehfMrRKHSIQcCImwHL&index=38
** ACCEPT THE SLOWNESS **
Top comments (0)