REST API based on FastAPI for generate your own short links.
- Docker
- Docker-compose
For local development:
- Poetry
- Put to project file .env with follow variables:
DOCKER_IMAGE_BACKEND=api
# Backend
HOST=localhost
PORT=80
DB_HOST=db
DB_NAME=links
DB_USER=admin
DB_PASSWORD=admin
TIME_CHECK_EXPIRED_LINKS_SECONDS=60
ACCESS_TOKEN_EXPIRE_MINUTES=3600
SHORT_LINK_EXPIRE_DAYS=1
# Postgres
POSTGRES_SERVER=db
POSTGRES_USER=admin
POSTGRES_PASSWORD=admin
POSTGRES_DB=links
# PgAdmin
PGADMIN_LISTEN_PORT=5050
[email protected]
PGADMIN_DEFAULT_PASSWORD=admin
- Make migration of database:
sudo docker-compose run backend alembic upgrade head
sudo docker-compose down
sudo docker-compose up -d
After few minutes will build image for rest api server. Also will pull images for other required services (PostgreSQL, pdAdmin) And then api will accessible on http://localhost:8080/api Documentation on http://localhost:8080/docs
For create new user send POST request to http://localhost:8080/api/sign-up
For login send POST request to http://localhost:8080/api/token
For get user information send GET request to http://localhost:8080/api/users/me
For create short_link send POST request to http://localhost:8080/api/links
For redirect to long link send GET request to http://localhost:8080/{short_link}
How long links live defines by SHORT_LINK_EXPIRE_DAYS in .env file.
Every TIME_CHECK_EXPIRED_LINKS_SECONDS links with exrired datetime will be deleted.
By default new created link has SHORT_LINK_EXPIRE_DAYS life.
For run test :
sudo docker-compose exec backend scripts/./start_tests.sh
For test pep8
sudo docker-compose exec backend flake8
Just start stack :
sudo docker-compose up -d
And work with code in project. Inside the container "backend" works :
uvicorn --port 80 --host 0.0.0.0 main:app --reload
It will reload server when changes will be found
For read logs:
sudo docker-compose logs backend