Skip to content

mtkhawaja/shortlink

Repository files navigation

shortlink

tests Docker Build codecov Supported Python Version

FastAPI Python Swagger

  • URL Shortener written in python.

Quick Start

Docker

Bash

Build Image & Run Container (sh)
docker build ./ -t shortlink/api -f ./Dockerfile && \
docker run -it --rm -p 80:8080 shortlink/api
Build Image & Run Tests (sh)
docker build --target tests ./ -t shortlink/api-tests -f ./Dockerfile && \
docker run  -it --rm shortlink/api-tests
Run Application with postgres & redis (sh)
docker-compose build && docker-compose up

Powershell

Build Image & Run Container (pwsh)
docker build ./ -t shortlink/api -f ./Dockerfile; `
if ($?) {`
  docker run -it --rm -p 80:8080  shortlink/api; `
}
Build Image & Run Tests (pwsh)
docker build --target tests ./ -t shortlink/api-tests -f ./Dockerfile; `
if ($?) {`
  docker run -it --rm shortlink/api-tests; `
}
Run Application with postgres & redis (pwsh)
docker-compose build; `
if ($?) {`
  docker-compose up; `
}

Environment Variables

General

Name Default Available Options Description
ENVIRONMENT DEV DEV, QA, STG, PROD Application environment.
CONVERSION_BASE 64 2, 8, 16, 32, 64 What base to use for shortening record keys.

Logging

Name Default Available Options Description
LOG_FILE /shortlink/logs/shortlink.log - Absolute path for log file. e.g. /var/log/short-link/application.log or E:\logs\short-link\application.log
LOG_LEVEL INFO DEBUG, INFO, WARNING, ERROR, CRITICAL See python logging levels for more information.
LOG_FORMAT %(asctime)s - [%(name)s] - [%(levelname)s] - %(message)s - Log msg format. With the default, formatting, a message may look like: 2022-02-13 13:53:13,463 - [src.main] - [INFO] - Application started.. See formatters for more information.
FF_CONSOLE_LOGGING True True, False If set to true, logs will be directed to console (stdout).

Caching

Name Default Available Options Description
REDIS_USER - - Redis username. e.g. short-link-redis-client
REDIS_PASSWORD - - Redis password. e.g. ^E05FNf8NHqfRxGIR
REDIS_HOST - - Redis host name. e.g. redis.example.com
REDIS_PORT - - Redis port. e.g 6379
REDIS_URL - - Redis connection string based on the following template: 'redis://<redis_user>:<self.redis_password>@<redis_host>:<self.redis_port>'. For example: 'redis://short-link-redis-client:^E05FNf8NHqfRxGIR@redis.example.com:6379' Note: If REDIS_URL is set, all other redis configuration options are overridden
FF_CACHING False True, False Set to False to disable all caching operations.

Database

Name Default Available Options Description
DB_URL - - Connection url for the database. For example: 'postgresql+psycopg2://short-link:secret@localhost/sl_db'. See database urls for more information
DB_CONNECT_ARGS - - Arguments passed directly to the DBAPIs connect() method See connect_args for more information
USE_IN_MEMORY_SQLITE True True, False If set to True, all other database settings are ignored and an in memory sqlite database is used.

License

Licence

Releases

No releases published

Packages

No packages published