Skip to content

caldaibis/url-shortener-service

Repository files navigation

FastAPI URL Shortener

A URL shortener crafted using FastAPI, SQLAlchemy, Pydantic, and Alembic combined with a PostgreSQL database.

Create the .env file

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.

Build the Docker Container

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

Run/Test the Application Locally

Utilize Postman or a similar tool to test the application's endpoints:

Shortening URLs

Make a POST request to shorten a URL:

POST http://localhost:80/shorten/
Content-Type: application/json

{
    "url": "https://www.example.com"
}

Using a Shortened URL

To navigate using a shortened URL, access:

GET http://localhost:80/urls/<shortened_hashcode>

Checking Stats of a Shortened URL

To check the statistics of a shortened URL, use:

GET http://localhost:80/urls/<shortened_hashcode>/stats

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •