Skip to content

Ngatiah/Simple-URLShortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple URLShortener

A simple URLShortener built using Django that encodes long URLs into compact, shareable links using Base62 encoding.


Why Base62?

Base62 encoding allows us to use a combination of characters and numbers, which includes:

  • A-Z (26 characters)
  • a-z (26 characters)
  • 0-9 (10 characters)

Total: 62 characters

So for a 7-character short URL, we can serve:

62^7 ~= 3500 billion URLs

which is quite enough in comparison to base10 (base10 only contains numbers 0-9 so you will get only 10M combinations).

This makes Base62 ideal for scalable short-link systems like Bitly or TinyURL.

BASE62 ENCODING LOGIC

def encode_base62(num: int) -> str:
    """Convert a positive integer to a Base62 string."""
    if num == 0:
        return ALPHABET[0]
    base62 = ""
    while num > 0:
        num, rem = divmod(num, 62)
        base62 = ALPHABET[rem] + base62
    return base62

HOW IT WORKS :

1.Type url : [https://www.youtube.com/watch?v=P2wLb1njn4I&list=RDMMP2wLb1njn4I&start_radio=1&pp=0gcJCacEOCosWNin ] in our template and click submit

2.The URL is saved in DB afterwhich its automatically assigned an auto-generated numeric ID i.e say 125.

3.The numeric ID then gets encoded into a Base62 short code i.e. abc123

4.The short code then gets appended to your custom domain to form i.e. https://yourapp.com/abc123

FUTURE ENHANCEMENTS

  • Add analytics dashboard (clicks by day, referrers of shortened urls)
  • Add QR code generation for short URLs
  • Enhance encoding logic ; switch to more secure, collision free IDs like hashids
  • Add user accounts and authenctication to ensure only registered users manage, delete and view statistics of their own shortened URLs

About

Simple URLShortener

Topics

Resources

Stars

Watchers

Forks