Thursday, 20 November 2025

How to run in Vs Code environment

 Here is a clean Compose-View–friendly blog page (NO HTML tags, NO Prism, NO scripts).

You can copy & paste directly into Blogger → Compose View.

I’ve written it specifically for undergraduate students, using VS Code, with module filenames, terminal commands, and step-by-step run instructions.


📘 FASTAPI — How to Run Modules 1 to 12 in VS Code (Beginner-Friendly Guide)

This guide teaches students how to run every module of your 12-part FastAPI course inside Visual Studio Code using Python + FastAPI + Uvicorn.

Each module is written as separate .py files so learners can run them individually as demos.


✅ 1. Install Requirements (Only Once)

Step 1 — Install Python 3.10+
Download from: https://www.python.org/downloads/

Step 2 — Install VS Code
Download from: https://code.visualstudio.com/

Step 3 — Install the VS Code Python Extension
Open VS Code → Extensions → search Python → Install.

Step 4 — Install FastAPI + Uvicorn
Open VS Code terminal:

pip install fastapi uvicorn

📂 Folder Structure for All Modules

Create a folder:

fastapi_course/

Inside it create the module files:

module01_basics.py
module02_path_params.py
module03_query_params.py
module04_request_body.py
module05_crud_inmemory.py
module06_pydantic_models.py
module07_error_handling.py
module08_middleware.py
module09_authentication.py
module10_background_tasks.py
module11_cors_staticfiles.py
module12_database_sqlite.py

(Use the code provided in your Module Posts.)


▶️ HOW TO RUN ANY MODULE (GENERAL RULE)

In VS Code:

  1. Open fastapi_course folder.

  2. Right-click a module file → click Open in Editor.

  3. Open a terminal:
    VS Code menu → Terminal → New Terminal

  4. Run:

uvicorn module_filename:app --reload

Example:

uvicorn module05_crud_inmemory:app --reload
  1. Open browser:

http://127.0.0.1:8000
  1. API docs:

http://127.0.0.1:8000/docs

🧪 MODULE-WISE RUN INSTRUCTIONS

Below are simplified commands for each module.


⭐ Module 1 — FastAPI Basics

Filename: module01_basics.py

Run:

uvicorn module01_basics:app --reload

Tests:


⭐ Module 2 — Path Parameters

Filename: module02_path_params.py

Run:

uvicorn module02_path_params:app --reload

Tests:

  • /items/5

  • /users/ramaswamy


⭐ Module 3 — Query Parameters

Filename: module03_query_params.py

Run:

uvicorn module03_query_params:app --reload

Tests:

  • /search?keyword=phone&limit=5


⭐ Module 4 — Request Body

Filename: module04_request_body.py

Run:

uvicorn module04_request_body:app --reload

Test in /docs:

  • POST → /create-user


⭐ Module 5 — CRUD (In-Memory DB)

Filename: module05_crud_inmemory.py

Run:

uvicorn module05_crud_inmemory:app --reload

Test in /docs:

  • POST → create item

  • GET → list items

  • PUT → update item

  • DELETE → remove item


⭐ Module 6 — Pydantic Models

Filename: module06_pydantic_models.py

Run:

uvicorn module06_pydantic_models:app --reload

Tests:

  • Validate input

  • Auto-docs with Pydantic schemas


⭐ Module 7 — Error Handling

Filename: module07_error_handling.py

Run:

uvicorn module07_error_handling:app --reload

Tests:

  • Trigger 404

  • Trigger validation errors


⭐ Module 8 — Middleware

Filename: module08_middleware.py

Run:

uvicorn module08_middleware:app --reload

Tests:

  • Check console for logs

  • Call routes to observe middleware behavior


⭐ Module 9 — Basic Authentication

Filename: module09_authentication.py

Run:

uvicorn module09_authentication:app --reload

Test:

  • /login in /docs

  • Use a token to access secured endpoints


⭐ Module 10 — Background Tasks

Filename: module10_background_tasks.py

Run:

uvicorn module10_background_tasks:app --reload

Test:

  • POST /send-email

  • Check console for background actions


⭐ Module 11 — CORS & Static Files

Filename: module11_cors_staticfiles.py

Run:

uvicorn module11_cors_staticfiles:app --reload

Test:

  • /static/...

  • Allowed origins via CORS


⭐ Module 12 — SQLite Database + CRUD

Filename: module12_database_sqlite.py

Run:

uvicorn module12_database_sqlite:app --reload

Test:

  • Create DB tables automatically

  • Perform database CRUD via /docs


🎯 CLASSROOM DEMO TIPS (Undergraduate Students)

✔ Run modules one by one → students clearly understand concepts
✔ Ask them to open /docs every time → visual understanding
✔ Let them edit small parts and run again
✔ Let students create their own API route as challenge


🎉 FINISHING THE COURSE

After completing Modules 1–12, students will know:

  • FastAPI Fundamentals

  • Path, Query, Body Inputs

  • CRUD APIs

  • Authentication

  • Middleware

  • Background Processing

  • CORS + Static Files

  • Database Integration (SQLite)



No comments:

Post a Comment

Diagnosis for running all Scripts

 Great — here is the complete ready-to-run folder structure for all 12 FastAPI modules , including: ✅ __init__.py (so Python treats folder...