Get Started with Short-URL
This quickstart guide will walk you through setting up the Short-URL API, creating your first short URL, and testing the core features. You’ll be up and running in under 5 minutes.Clone and Install
Clone the repository and install dependencies.
Requirements: Python 3.11+ and MongoDB must be installed on your system.
Configure Environment Variables
Set up your environment variables for the API.
Environment Variable Details
Environment Variable Details
- MONGO_URI (required): MongoDB connection string
- SECRET_KEY (required): Secret key for JWT token signing
- TOKEN_EXPIRE (optional): Token expiration time in minutes (default: 5)
- SURL_BASE (required): Base URL for shortened links
- ALLOWED_ORIGINS (optional): CORS origins (default: *)
- URL_BLACKLIST (optional): Comma-separated list of blacklisted URL substrings
Start the Server
Launch the FastAPI application with Uvicorn.Your API will be available at
http://127.0.0.1:8000Create Your First Short URL
Use the
/create endpoint to generate a short URL.- cURL
- Python
- JavaScript
Expected Response
Expected Response
Test the Redirect
Access your short URL to test the redirect.You should see a 307 redirect to
https://example.comAuthenticate to Manage Your URL
Login to receive a JWT access token for managing your URL.
Expected Response
Expected Response
Next Steps
Now that you have Short-URL running, explore these resources:Authentication Guide
Deep dive into JWT authentication, token refresh, and security best practices.
API Reference
Explore all available endpoints with detailed examples and response schemas.
Deployment Guide
Learn how to deploy Short-URL to production with proper configuration.
URL Management
Learn about URL lifecycle, validation rules, and advanced features.
Common Issues
MongoDB Connection Failed
MongoDB Connection Failed
Ensure MongoDB is running and the
MONGO_URI environment variable is correctly set.Token Expired Error
Token Expired Error
Access tokens expire after the time specified in
TOKEN_EXPIRE (default: 5 minutes).Use the /refresh_token endpoint to get a new token without re-authenticating.URL Code Already Exists
URL Code Already Exists
Each
url_code must be unique. Choose a different code or delete the existing URL first.Invalid URL Code Format
Invalid URL Code Format
URL codes must:
- Be 3-20 characters long
- Contain only alphanumeric characters, hyphens, and underscores
- Not be a reserved keyword (docs, redoc, create, login, delete, pause, resume, etc.)