Skip to content

Parth-Dholariya/URL-Shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener (Flask)

A simple Python Flask URL shortener with SQLite storage, custom alias validation, click analytics, and a REST API.

Setup

  1. Create a virtual environment:

    python -m venv .venv
    .\.venv\Scripts\Activate.ps1
  2. Install dependencies:

    pip install -r requirements.txt
  3. Run the app:

    python app.py
  4. Open http://127.0.0.1:5000 in your browser.

Features

  • Shorten URLs with a generated code.
  • Optional custom alias support.
  • Click counting for each short link.
  • Recent links view with analytics.
  • REST API for programmatic creation and inspection.

API

Create a short URL

POST http://127.0.0.1:5000/api/shorten

Request JSON:

{
  "long_url": "https://example.com/page",
  "custom_alias": "example-link"
}

Response JSON:

{
  "code": "example-link",
  "long_url": "https://example.com/page",
  "short_url": "http://127.0.0.1:5000/example-link",
  "clicks": 0
}

Inspect a short URL

GET http://127.0.0.1:5000/api/urls/<code>

Response JSON includes code, long_url, clicks, and short_url.

Deploying to AWS

This project includes a Dockerfile and Procfile, so it can run on AWS Elastic Beanstalk with Docker or the Python platform.

Option 1: Elastic Beanstalk (Docker)

  1. Install and configure the AWS CLI and EB CLI.

  2. Initialize the app:

    eb init -p docker url-shortener-app
  3. Create and deploy an environment:

    eb create url-shortener-prod
    eb deploy
  4. Open the deployed site:

    eb open

Option 2: Elastic Beanstalk (Python)

If you prefer the Python platform, Elastic Beanstalk can use requirements.txt, app.py, and Procfile directly.

  1. Initialize with Python:

    eb init -p python-3.12 url-shortener-app
  2. Deploy as above.

Option 3: ECS / Fargate

  1. Build and push the Docker image to ECR.
  2. Create an ECS service with the image.
  3. Expose port 5000 via a load balancer.

Important note

  • urls.db is a local SQLite file. For production, use a networked database like Amazon RDS or DynamoDB if you need durability across container restarts and multiple instances.

Notes

  • Custom alias validation: 3-32 characters, letters, numbers, hyphens, and underscores.
  • Data is stored in urls.db by default.

About

project that help to shorten your long url into small encoded url

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors