The short_url
service is a backend API for shortening URLs and retrieving information about them. It uses SQLite for data persistence and provides RESTful endpoints to create, access, and track shortened URLs.
This module is part of the orchestrator_api project, which integrates multiple services to provide a unified platform for managing tasks and shortening URLs.
- Shorten long URLs into short, unique identifiers.
- Redirect users from a short URL to the original URL.
- Retrieve statistics about shortened URLs, such as the original URL and its identifier.
- Python 3.9+
- Pip: Install Pip
- Docker (optional): For containerized deployment.
- Default:
http://localhost:8001
-
Shorten a URL
- POST
/shorten
- Request Body:
{ "url": "https://example.com" }
- Response:
{ "short_url": "http://localhost:8001/abc123" }
- POST
-
Redirect to Original URL
- GET
/{short_id}
- Example:
GET /abc123
- Redirects to the original URL.
- GET
-
Get URL Statistics
- GET
/stats/{short_id}
- Example:
GET /stats/abc123
- Response:
{ "short_id": "abc123", "full_url": "https://example.com" }
- GET
-
Clone the repository:
git clone https://github.com/ivr0ma/shorturl_app.git cd shorturl_app
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
uvicorn main:app --host 0.0.0.0 --port 8001
-
Access the API: Open your browser or API client (e.g., Postman) and navigate to
http://localhost:8001/docs
for API documentation.
-
Build the Docker image:
docker build -t short_url:latest .
-
Run the container:
docker run -d --name short_url -p 8001:80 -v shorturl_data:/app/data short_url:latest
-
Access the API: Open your browser or API client and navigate to
http://localhost:8001/docs
for API documentation.