Skip to content

pipinstalled/ShortenURL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShortenURL

Short url generator

Setup

  1. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file:
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
  1. Create database:
createdb shortenurl
  1. Run migrations:
cd app
alembic upgrade head

Run

cd app
uvicorn main:app --reload

API available at http://localhost:8000 Documentation at http://localhost:8000/docs

API Endpoints

POST /shorten

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"
}

GET /{short_code}

Redirect to the original URL.

GET /stats/{short_code}

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
}

Tests

cd app
pytest tests/

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published