Skip to content

URL Shortener: A Python-Flask based web application that transforms long, unwieldy URLs into concise, easy-to-share links. Developed in my free time.

Notifications You must be signed in to change notification settings

sandordaroczi/URL-Shortener-in-Python-Flask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL shortener service in Python

This is an URL shortener service written using Python / Flask.

Project details:

  • Language: Python
  • Framework: Flask
  • IDE: PyCharm
  • Created on Windows 10

Setup

The setup instructions are for Windows OS.

  1. Navigate to the directory of the downloaded project
  2. Make sure Python is installed (version >= 3.7.4)
  3. Open command line from the directory, and run the following commands:
  • pip install virtualenv
  • python -m virtualenv ./
  • pip install -r requirements.txt
  • python app.py

Then, open a browser of your choice and go to http://127.0.0.1:7777/.

Endpoints

I. /encode/

  • Given a long URL argument as e.g. http://127.0.0.1:7777/encode?url=https://wikipedia.org, it returns a JSON containing a short URL of the form http://127.0.0.1:7777/6M0qc corresponding to the long link provided, or an error message if the conversion could not be performed.

II. /decode/

  • Given a short URL argument as e.g. http://127.0.0.1:7777/decode?url=http://127.0.0.1:7777/6M0qc, it returns a JSON containing the corresponding decoded long URL, if it exists, or an error message otherwise.

III. /redirect/

  • This endpoints reads in a short_url as e.g. http://127.0.0.1:7777/redirect?url=http://127.0.0.1:7777/6M0qc, then, similarly to the decode endpoint, it finds the corresponding long_url if has already been encoded. Then instead of just returning it, the endpoint will redirect the page to the given long_url.

Algorithm for generating the short URLs

The generator algorithms simply generates a sequence of random characters (lowercase letters + uppercase letters + numbers) with length specified by the num_chars variable, and then creates a string via concatenating the base_url with the encoding. This string will be stored as the encoded URL in two dictionaries (to ensure an average lookup time of O(1))

About

URL Shortener: A Python-Flask based web application that transforms long, unwieldy URLs into concise, easy-to-share links. Developed in my free time.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published