
- Implemented user authentication with JWT tokens - Created product management endpoints - Added shopping cart functionality - Implemented order management system - Setup database models with SQLAlchemy - Created alembic migrations - Added health check endpoint generated with BackendIM... (backend.im)
E-Commerce API
A RESTful API for e-commerce applications built with FastAPI and SQLite. This API provides endpoints for user authentication, product management, shopping cart functionality, and order processing.
Features
- User authentication with JWT tokens
- Product catalog with filtering capabilities
- Shopping cart functionality
- Order management and processing
- Admin routes for managing products and orders
- Data persistence with SQLite
- Alembic migrations for database version control
API Endpoints
Authentication
POST /api/v1/auth/register
- Register a new userPOST /api/v1/auth/login
- Login and get access token
Users
GET /api/v1/users/me
- Get current user informationPUT /api/v1/users/me
- Update current user informationGET /api/v1/users/{user_id}
- Get user by ID (admin or self only)GET /api/v1/users/
- List all users (admin only)DELETE /api/v1/users/{user_id}
- Delete a user (admin only)
Products
GET /api/v1/products/
- List all active products with filtering optionsPOST /api/v1/products/
- Create a new product (admin only)GET /api/v1/products/{product_id}
- Get product detailsPUT /api/v1/products/{product_id}
- Update a product (admin only)DELETE /api/v1/products/{product_id}
- Soft delete a product (admin only)
Cart
GET /api/v1/cart/
- Get current user's cart itemsPOST /api/v1/cart/
- Add item to cartPUT /api/v1/cart/{cart_item_id}
- Update cart item quantityDELETE /api/v1/cart/{cart_item_id}
- Remove item from cartDELETE /api/v1/cart/
- Clear cart
Orders
GET /api/v1/orders/
- List user's orders (or all orders for admin)POST /api/v1/orders/
- Create a new order from cart or specified itemsGET /api/v1/orders/{order_id}
- Get order details with itemsPUT /api/v1/orders/{order_id}/status
- Update order status (admin only)DELETE /api/v1/orders/{order_id}
- Cancel a pending order
Health Check
GET /health
- Check API health status
Getting Started
Prerequisites
- Python 3.8 or higher
Installation
-
Clone the repository
git clone <repository-url>
-
Install dependencies
pip install -r requirements.txt
-
Initialize the database
alembic upgrade head
-
Run the server
uvicorn main:app --reload
API Documentation
When the server is running, you can access the interactive API documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Environment Variables
You can customize the following settings in the app/core/config.py
file:
SECRET_KEY
: Secret key for JWT token generationACCESS_TOKEN_EXPIRE_MINUTES
: Token expiration timeBACKEND_CORS_ORIGINS
: CORS origin settings
Description
Languages
Python
98.8%
Mako
1.2%