In this beginner-friendly tutorial, you’ll learn how to build a simple REST API using FastAPI and test it using Postman.
We’ll create, read, update, and delete (CRUD) items in memory.
Prerequisites
Before you begin, make sure you have:
-
Python 3.10 or newer is installed
-
Basic knowledge of JSON and HTTP requests
-
Postman installed for API testing
Step 1 — Create Project Folder and Virtual Environment
Open your Terminal and run:
After activation, your terminal prompt will show
(venv)indicating you’re inside the virtual environment.
Step 2 — Install FastAPI and Uvicorn
With the virtual environment activated, run:
-
FastAPI is the framework to build the API.
-
Uvicorn is the ASGI server that runs your app.
Step 3 — Create main.py with API Code
Create a file named main.py inside fastapi_api folder and paste this code:
Step 4 — Run FastAPI Server
Run the server with this command (inside the project folder and with your virtual environment activated):
Step 5 — Access Interactive API Documentation
Open these URLs in your browser:
-
Swagger UI: http://127.0.0.1:8000/docs
-
ReDoc: http://127.0.0.1:8000/redoc
You can test all endpoints interactively here without Postman.
Step 6 — Test API Endpoints with Postman
Use Postman to test these endpoints:
🟢 Create Item (POST)
-
URL:
POST http://127.0.0.1:8000/items -
Headers:
Content-Type: application/json -
Body (raw JSON):
-
Response:
🔵 Get Item (GET)
-
URL:
GET http://127.0.0.1:8000/items/1 -
Response:
🟠 Update Item (PUT)
-
URL:
PUT http://127.0.0.1:8000/items/1 -
Headers:
Content-Type: application/json -
Body (raw JSON):
-
Response:
🔴 Delete Item (DELETE)
-
URL:
DELETE http://127.0.0.1:8000/items/1 -
Response:
Status code204 No Content(no body)
⚪ Get All Items (GET)
-
URL:
GET http://127.0.0.1:8000/items -
Response Example:
Step 7 — Summary
| Framework | Features | Documentation |
|---|---|---|
| Flask | Lightweight, beginner-friendly | flask.palletsprojects.com |
| FastAPI | High-performance, async-ready, built-in docs, validation | fastapi.tiangolo.com |

