/url_shortener

A minimal dockerized URL shortener API.

Primary LanguagePython

URL Shortener API

A minimal dockerized URL shortener API.

Contents

  1. Installing
  2. Running Tests
  3. Using the API
  4. Project Structure

Installing

Before building and running the services; let's create .env file in order to set environment variables.

echo "
APP_HOST=0.0.0.0
APP_PORT=8000

FLASK_APP=app
FLASK_ENV=development

SECRET_KEY=VerySecretKey
" > .env

.env file must be created in the top-most directory (along with docker-compose.yml).

Now we can build the app image and start the services.

docker-compose build
docker-compose up -d

Running Tests

You can easily run the tests by running:

docker-compose run --rm app pytest --verbose --cov=.

Using the API

Redirect Endpoint [/string:code (GET)]
curl -v -X GET http://localhost:8000/<string:code>
Shortening URL Endpoint [/shorten (POST)]
curl -v -X POST -d url=http://example.com http://localhost:8000/shorten

Project Structure

├── Dockerfile
├── README.md
├── app
│   ├── app
│   │   ├── __init__.py
│   │   ├── models.py
│   │   ├── settings.py
│   │   ├── utils.py
│   │   └── views.py
│   ├── pytest.ini
│   ├── requirements.txt
│   └── tests
│       ├── __init__.py
│       ├── test_utils.py
│       └── test_views.py
├── docker-compose.override.yml
└── docker-compose.yml