A URL shortener crafted using FastAPI, SQLAlchemy, Pydantic, and Alembic combined with a PostgreSQL database.
The first thing one needs to do is to create an .env file in the root folder of this repo. Copy the keys from .env.dist and fill in the values according to your local database connection arguments.
Two different containers are composed together using docker compose
. One for the application itself, and one separately for the PostgreSQL database. To build and run the Docker containers, execute the following command:
docker compose up --build
Utilize Postman or a similar tool to test the application's endpoints:
Make a POST request to shorten a URL:
POST http://localhost:80/shorten/
Content-Type: application/json
{
"url": "https://www.example.com"
}
To navigate using a shortened URL, access:
GET http://localhost:80/urls/<shortened_hashcode>
To check the statistics of a shortened URL, use:
GET http://localhost:80/urls/<shortened_hashcode>/stats