This is a simple FastAPI project demonstrating basic CRUD (Create, Read, Update, Delete) operations using an in-memory database.
- Python 3.7 or higher
- FastAPI
- Uvicorn (ASGI server)
Clone the repository (or create your own project with the files provided here).
Install the dependencies:
pip install fastapi uvicornRun the FastAPI application using Uvicorn:
uvicorn main:app --reloadThis will start the application on http://127.0.0.1:8000.
Access the API documentation:
FastAPI automatically generates interactive API documentation. You can access it at:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
Retrieve a list of all items.
curl -X GET "http://127.0.0.1:8000/items" -H "accept: application/json"Create a new item by sending a POST request with a JSON body.
curl -X POST "http://127.0.0.1:8000/items" -H "Content-Type: application/json" -d '{
"id": 1,
"name": "Laptop",
"description": "A high-performance laptop",
"price": 1200.00
}'Retrieve a specific item by its id.
curl -X GET "http://127.0.0.1:8000/items/1" -H "accept: application/json"Update an existing item by sending a PUT request with updated item data in JSON format.
curl -X PUT "http://127.0.0.1:8000/items/1" -H "Content-Type: application/json" -d '{
"id": 1,
"name": "Gaming Laptop",
"description": "A high-performance gaming laptop",
"price": 1500.00
}'Delete a specific item by its id.
curl -X DELETE "http://127.0.0.1:8000/items/1" -H "accept: application/json"This project is licensed under the MIT License.