Skip to content

mrigor/url-shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

~ How do I use it?

  * Install Flask (http://flask.pocoo.org/docs/installation/#installation)
  * Start the Sqllite DB from python interpreter:
    >>>from url_shortener import init_db; init_db()
  * Run a local server with 'python url_shortener.py'
  * Now you can send JSON data to http://localhost:5000/shorten_url
    Example:
      "{'long_url': 'http://google.com/'}"

    Custom short urls can be requested by providing `custom_short_code` key in your request.
    Example:
      "{'custom_short_code': 'abcdef', 'long_url': 'http://google.com/'}"

    Response is in JSON format with 'success' and 'short_code' keys.
    If an error occurs, a 'message' key will contain an explanation.

~ How do I run tests?

  `python tests.py`

~ Design notes

  * Caching server such as Redis could be used to store existing URLs. This would decrease latency but requires large memory consumption and supporting scripts to warm the cache on cold starts.
  * I chose to use 302 temporary redirect status code because users with custom urls will probably want to update their long urls.
  * With Postgres we could avoid insert/last_insert_rowid()/update overhead by using sequences for url hashing. With use of 'nextval()' we can be sure to avoid collisions and only perform an insert with precomputed hash. (http://www.postgresql.org/docs/8.1/static/sql-createsequence.html)

About

Simple url shortener using Flask

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages