Workshop Title : FAST API
-----------------------------------------------------------------------------------
--
What is API?
API stands for Application Programming Interface.
API's are used inorder to have communication between two applications
What is web application?
web application is collection of programs, which includes
1. front end
2. backend
It is an application which is accessible from browser
web application is internet or intranet application.
What is web service?
service is a program which is accessed using internet
service is a program which is access by different applications
1. Web application
2. Mobile application
3. Destop application
4. AI Application
How to develop this web services or web api?
REST --> representational state transfer architecture style
REST API --> A REST API is an application programming interface it defines
designing
principles.
1. FAST API --> REST API
2. DRF --> Django Rest Framework
Django Flask FAST API
web web application REST API
application framework web framework
framework used for developing for developing
used for web application web services/api's
developing micro services
web app's
fullstack mircro framework
framework
What is FastAPI?
FastAPI is a modern, fast (high-performance), web framework for building APIs with
Python.
It is built on Starlette (for web parts) and Pydantic (for data validation).
It is asynchronous by design, meaning it works really well with Python’s async and
await.
Key features:
Fast → very high performance, almost like Node.js and Go (thanks to ASGI +
uvicorn).
Automatic validation → checks request & response data using Pydantic.
Interactive docs → automatically generates Swagger UI & ReDoc for API testing.
Asynchronous support → perfect for modern apps needing concurrency.
1. Web APIs (Backend Services)
RESTful APIs for web apps or mobile apps.
2. Microservices
Lightweight, fast backend services communicating with each other.
3. Machine Learning / AI APIs
Deploy ML models as REST APIs.
--------------------------------------------------------------------------------
Basic Steps for Developing with FastAPI
1. Install FastAPI and Uvicorn
FastAPI is the framework, and Uvicorn is the ASGI server to run it.
Creating simplefastapi application(main.py)
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Hello, FastAPI!"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
return {"item_id": item_id, "q": q}
Run the app
uvicorn main:app --reload
Testing using requests
import requests
BASE_URL = "http://127.0.0.1:8000"
def test_root():
response = requests.get(f"{BASE_URL}/")
print(response.status_code, response.json())
def test_item():
response = requests.get(f"{BASE_URL}/items/42?q=testing")
print(response.status_code, response.json())
if __name__ == "__main__":
test_root()
test_item()