babyshortener
Simple URL shortener implemented using Flask
Persistence layer provided by SQLAlchemy (flask_sqlalchemy
). API Resource class provided by flask-restful
How to install?
Run:
git clone git@github.com:mnowotka/babyshortener.git
cd babyshortener
pip install .
pip install -r requirements.txt
Or:
pip install git+https://github.com/mnowotka/babyshortener.git
How to test?
Run:
python tests/test_shortener.py
How to run development server?
If installed by cloning GitHub
repo, add project root directory to PYTHONPATH
and run:
python babyshortener/run_shortener.py
If installed via pip
, the run_shortener
command should be available
curl
?
How to make request using To shorten:
curl -H "Content-Type: application/json" -X POST -d '{"url": "www.google.com"}' http://localhost:5000/shorten_url
To redirect:
curl http://localhost:5000/1VV
How to configure to scale?
-
Provide your own settings file and configure
SQLALCHEMY_DATABASE_URI
to point to the production database -
Deploy behind gunicorn & NGINX (https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-14-04)
export BABYSHORTENER_SETTINGS=/path/to/settings.cfg
gunicorn --bind localhost:8080 --workers 4 'babyshortener.run_shortener:main'
-
Deploy on multiple machines behind a load balancer
-
Add a cache layer