Short url generator
- Install dependencies:
pip install -r requirements.txt- Create a
.envfile:
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=shortenurl
APP_NAME=URL Shortener
BASE_URL=http://localhost:8000
SHORT_CODE_LENGTH=6- Create database:
createdb shortenurl- Run migrations:
cd app
alembic upgrade headcd app
uvicorn main:app --reloadAPI available at http://localhost:8000
Documentation at http://localhost:8000/docs
Create a short URL.
Request:
{
"original_url": "https://example.com"
}Response:
{
"id": 1,
"original_url": "https://example.com",
"short_code": "http://localhost:8000/abc123",
"created_at": "2024-01-01T12:00:00Z",
"message": "Short url created successfully"
}Redirect to the original URL.
Get statistics for a shortened URL.
Response:
{
"original_url": "https://example.com",
"short_code": "abc123",
"created_at": "2024-01-01T12:00:00Z",
"visits_count": 42
}cd app
pytest tests/