A URL shortener service built with FastAPI, PostgreSQL, and Auth0 for authentication. This service allows users to shorten URLs, retrieve the original URLs, list their shortened URLs, and delete them.
- Shorten URLs with a unique key.
- Retrieve the original URL from a shortened key.
- List all shortened URLs with pagination.
- Delete shortened URLs.
- Authentication using JWT from client application.
git clone https://github.com/akinolaemmanuel49/URL-Shortener-Service.git
cd URL-Shortener-Service
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
pip install -r requirements.txt
-
Create an
.env
file in the root directory and add the following environment variables:VERSION=1.0 BASE_URL_PATH=/api SHORTENED_URL_BASE=http://localhost:8000/ TOKEN_URI=http://localhost:8000/api/auth/token LOGOUT_REDIRECT_URI=http://localhost:8000 APP_SECRET_KEY=your_secret_key APP_NAME=URL Shortener Service ADMIN_EMAIL=admin@example.com ITEMS_PER_PAGE=10 DATABASE=postgresql+asyncpg://username:password@localhost/database_name PG_USERNAME=username PG_PASSWORD=password PG_DATABASE_NAME=database_name PG_HOST=localhost CACHE_HOST=localhost CACHE_PORT=6379 CACHE_USERNAME=username CACHE_PASSWORD=password CACHE_DB='0' AUTH0_DOMAIN=your-auth0-domain AUTH0_CLIENT_ID=your-auth0-client-id AUTH0_CLIENT_SECRET=your-auth0-client-secret AUTH0_ALGORITHMS=RS256 AUTH0_API_AUDIENCE=your-api-audience AUTH0_ISSUER=your-auth0-issuer
-
Run Database Migrations
fastapi run
-
Start the Application
fastapi run
-
Access the Application
Navigate to
http://localhost:8000
in your browser. You can use the provided endpoints to interact with the service.
-
Endpoint:
POST /api/shorten/
-
Query Parameter:
url
(required): The original URL to be shortened.
-
Response:
{ "shortened_url": "http://localhost:8000/abc123", "original_url": "http://example.com", "created": true }
-
Endpoint:
GET /api/shorten/
-
Query Parameters:
limit
(optional): Number of results per page.offset
(optional): Starting point for pagination.
-
Response:
{ "total": 1, "urls": [ { "shortened_url": "http://localhost:8000/abc123", "original_url": "http://example.com" } ] }
-
Endpoint:
DELETE /api/shorten/{key}
-
Response:
{ "message": "successfully deleted" }
Contributions are welcome! Please open an issue or submit a pull request to the repository.
This project is licensed under the MIT License. See the LICENSE file for details.