URL Shortener REST API

Installation

Locally

  • Create a python virtual environment.
  • Update the SHORTENER_WEB_SERVER value in the .flaskrun file.
  • Install dependencies
pip install -r requirements.txt
  • Run flask server
flask run --host=0.0.0.0

Using Docker

  • Update the SHORTENER_WEB_SERVER value in the .flaskrun file.
  • Create a urlshortener container
docker-compose up

Testing

Sample curl command

curl http://127.0.0.1:5000/api/shorten -X POST -H 'Content-Type:application/json' -d '{"url":"https://google.com"}'  

Using pytest

  • Install dev dependencies
pip install -r requirements_dev.txt
  • Run test cases
pytest -v