This is a simple URL shortener application built using Python, FastAPI, and SQLite. It allows users to shorten long URLs into shorter, more manageable links.
- Method: POST
- Endpoint:
/
- Description: Create a shortened URL.
- Request Body:
original_url
(string): The original long URL to be shortened.
- Response:
url
(string): The shortened URL.
- Method: GET
- Endpoint:
/{key}
- Description: Redirects the user to the original URL associated with the provided key.
- Parameters:
key
(string): The key associated with the shortened URL.
- Response:
- Redirects the user to the original URL if not expired and active.
- Method: GET
- Endpoint:
/admin/{key}
- Description: Retrieve details about the shortened URL.
- Parameters:
key
(string): The key associated with the shortened URL.
- Response:
- JSON object containing details about the shortened URL:
original_url
(string): The original long URL.url
(string): The shortened URL.created
(int): The time the shortened url was createdexpiry
(integer): The expiration date of the shortened URL.active
(boolean): Indicates if the shortened URL is active.visits
(int): Indicates the number of times this link has been visited
- JSON object containing details about the shortened URL:
-
Clone the repository:
git clone https://github.com/VictorLoy/url-shortener.git
-
Navigate to the project directory:
cd url-shortener
-
Create a virtual environment (optional but recommended):
python -m venv venv
-
Activate the virtual environment:
On Windows:
venv\Scripts\activate
On Linux/macOS:
source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Start the FastAPI server:
uvicorn main:app --reload
-
Use the provided endpoints to interact with the URL shortener.
This project uses SQLite as its database to store URLs and their corresponding shortened versions. The database file is shortener.db
located in the project directory.
This project is licensed under the MIT License - see the LICENSE file for details.