Skip to content

sachin8808/CodeAlpha_URL_Shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener

A simple URL shortener built with Flask and SQLite. Paste in a long link, get back a short one that redirects to the original when visited. Built this as part of my CodeAlpha internship.

What it does

  • Shortens any long URL into a random 6-character code
  • Lets you set your own custom short code instead of a random one, if you want
  • Redirects yoursite.com/abc123 straight to the original long URL
  • Tracks how many times each short link has been clicked
  • If you shorten the same URL twice, it just gives you back the same short code instead of creating a duplicate
  • Has a small web page to test it out — no need to use Postman or curl

Tech used

  • Backend: Python (Flask)
  • Database: SQLite
  • Frontend: Plain HTML, CSS and JavaScript (no frameworks used)

Running it locally

  1. Clone the repo
git clone https://github.com/sachin8808/CodeAlpha_URL_Shortener.git
cd CodeAlpha_URL_Shortener
  1. Install the dependencies
pip install -r requirements.txt
  1. Run the app
python app.py
  1. Open your browser and go to
http://127.0.0.1:5000

That's it, no extra config or environment variables needed. The SQLite database file gets created automatically the first time you run it.

API endpoints

Method Route What it does
POST /api/shorten Send { "url": "..." } (and optionally "custom_code") to get a short link back
GET /<short_code> Redirects to the original long URL
GET /api/urls Lists all shortened URLs
GET /api/urls/<short_code> Get info about one specific short link
DELETE /api/urls/<short_code> Delete a short link

Example request

POST /api/shorten
Content-Type: application/json

{
  "url": "https://www.example.com/some/really/long/path?x=1"
}

Response:

{
  "short_code": "aZ3kT9",
  "short_url": "http://127.0.0.1:5000/aZ3kT9",
  "original_url": "https://www.example.com/some/really/long/path?x=1"
}

Things I'd like to add later

  • User accounts, so people can manage their own links
  • Expiry dates for links
  • QR code generation for each short URL
  • Better analytics (right now it only counts total clicks, nothing about when or from where)
  • Deploying it somewhere so it's not just localhost

Notes

This was mainly a learning project to get comfortable with building a small backend from scratch — routing, a database, some basic validation, and a minimal frontend to tie it together. Feedback welcome if you spot something that could be done better.

About

A simple URL shortener built with Flask and SQLite

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors