Skip to content

About

A URL shortening service with a caching layer and click analytics, built with Flask and SQLite.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener with Analytics

A URL shortening service with a caching layer and click analytics, built with Flask and SQLite.

Features

  • Generates short codes for long URLs
  • Redirects with a cache layer in front of the database (pattern identical to Redis GET/SET + TTL)
  • Tracks click counts per short link

Stack

Flask · SQLite · (cache layer designed to swap in Redis directly)

Run it

pip install flask
python app.py

Example usage

curl -X POST http://localhost:5002/api/shorten -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/some/very/long/path"}'
# -> {"short_code": "aZ3kT9", "short_url": "/r/aZ3kT9"}

curl -L http://localhost:5002/r/aZ3kT9   # redirects to the original URL

curl http://localhost:5002/api/stats/aZ3kT9   # {"code": "aZ3kT9", "clicks": 1, ...}

Porting to Redis

Replace the CACHE dict + cache_get/cache_set functions with a redis.Redis() client:

r.set(code, target, ex=60)   # cache_set
r.get(code)                  # cache_get

The rest of the app is unchanged — this is exactly why the cache logic is isolated into its own two functions.

About

A URL shortening service with a caching layer and click analytics, built with Flask and SQLite.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages