Prerequisites
Before installing Short-URL, ensure you have the following installed on your system:Required Software
Python 3.11+
Short-URL requires Python 3.11 or higher. Check your version with
python --versionMongoDB
MongoDB 4.0 or higher (local installation or MongoDB Atlas)
pip
Python package manager (usually included with Python)
Git
For cloning the repository
Check Your Python Version
Python 3.11.0 or higher.
Installation Methods
- Standard Installation
- Virtual Environment (Recommended)
Install Dependencies
Install all required packages from requirements.txt:This will install:
- fastapi (0.119.0) - Web framework
- motor (3.7.1) - Async MongoDB driver
- pymongo (4.15.3) - MongoDB Python driver
- pydantic (2.12.2) - Data validation
- python-jose (3.5.0) - JWT token handling
- passlib (1.7.4) - Password hashing
- uvicorn (0.37.0) - ASGI server
- python-dotenv (1.1.1) - Environment variable management
- And other dependencies
MongoDB Setup
- Local MongoDB
- MongoDB Atlas (Cloud)
Environment Configuration
Environment Variables Reference
| Variable | Required | Default | Description |
|---|---|---|---|
MONGO_URI | Yes | - | MongoDB connection string |
SECRET_KEY | Yes | - | JWT token signing key (must be secure) |
TOKEN_EXPIRE | No | 5 | Token expiration time in minutes |
SURL_BASE | Yes | - | Base URL for generated short links |
ALLOWED_ORIGINS | No | * | CORS allowed origins (comma-separated) |
URL_BLACKLIST | No | "" | Blacklisted URL patterns (comma-separated) |
Start the Server
Verify Installation
Check Database Connection
If this fails, check your MongoDB connection string and ensure MongoDB is running.
Access API Documentation
Open your browser and visit:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
Troubleshooting
ModuleNotFoundError: No module named 'fastapi'
ModuleNotFoundError: No module named 'fastapi'
Problem: FastAPI or other dependencies not installed.Solution:If using a virtual environment, make sure it’s activated first.
Database connection failed
Database connection failed
Problem: Cannot connect to MongoDB.Solutions:
-
Local MongoDB: Ensure MongoDB is running
-
MongoDB Atlas:
- Check your connection string is correct
- Verify network access settings allow your IP
- Confirm database user credentials are correct
-
Check MONGO_URI format:
Token validation errors
Token validation errors
Problem: JWT token creation or validation failing.Solution: Ensure Generate a new one if needed:
SECRET_KEY is set in your .env file:Port already in use
Port already in use
Problem: Port 8000 is already occupied.Solution: Use a different port:Or find and kill the process using port 8000:
CORS errors in browser
CORS errors in browser
Problem: Cross-origin requests blocked.Solution: Update
ALLOWED_ORIGINS in .env:URL code validation fails
URL code validation fails
Problem: Cannot create URL with certain codes.Solution:
- URL codes must be 3-20 characters
- Only alphanumeric, hyphens, and underscores allowed
- Cannot use reserved keywords:
docs,redoc,create,login,delete,pause,resume,details,refresh_token,change_password,reset_hits,change_url,validate_token,health
mylink, link-123, my_url_2024Next Steps
Quickstart Guide
Follow the quickstart to create your first short URL
API Reference
Explore all available endpoints and features
Authentication
Learn about JWT authentication and token management
Deployment
Deploy Short-URL to production