Skip to content

akinolaemmanuel49/URL-Shortener-Service

Repository files navigation

URL Shortener Service

A URL shortener service built with FastAPI, PostgreSQL, and Auth0 for authentication. This service allows users to shorten URLs, retrieve the original URLs, list their shortened URLs, and delete them.

Features

  • Shorten URLs with a unique key.
  • Retrieve the original URL from a shortened key.
  • List all shortened URLs with pagination.
  • Delete shortened URLs.
  • Authentication using JWT from client application.

Table of Contents

Installation

Clone the Repository

git clone https://github.com/akinolaemmanuel49/URL-Shortener-Service.git
cd URL-Shortener-Service

Create a Virtual Environment

python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`

Install Dependencies

pip install -r requirements.txt

Configuration

  1. Create an .env file in the root directory and add the following environment variables:

    VERSION=1.0
    BASE_URL_PATH=/api
    SHORTENED_URL_BASE=http://localhost:8000/
    TOKEN_URI=http://localhost:8000/api/auth/token
    LOGOUT_REDIRECT_URI=http://localhost:8000
    APP_SECRET_KEY=your_secret_key
    
    APP_NAME=URL Shortener Service
    ADMIN_EMAIL=admin@example.com
    ITEMS_PER_PAGE=10
    DATABASE=postgresql+asyncpg://username:password@localhost/database_name
    
    PG_USERNAME=username
    PG_PASSWORD=password
    PG_DATABASE_NAME=database_name
    PG_HOST=localhost
    
    CACHE_HOST=localhost
    CACHE_PORT=6379
    CACHE_USERNAME=username
    CACHE_PASSWORD=password
    CACHE_DB='0'
    
    AUTH0_DOMAIN=your-auth0-domain
    AUTH0_CLIENT_ID=your-auth0-client-id
    AUTH0_CLIENT_SECRET=your-auth0-client-secret
    AUTH0_ALGORITHMS=RS256
    AUTH0_API_AUDIENCE=your-api-audience
    AUTH0_ISSUER=your-auth0-issuer
  2. Run Database Migrations

    fastapi run

Usage

  1. Start the Application

    fastapi run
  2. Access the Application

    Navigate to http://localhost:8000 in your browser. You can use the provided endpoints to interact with the service.

API Documentation

Shorten URL

  • Endpoint: POST /api/shorten/

  • Query Parameter:

    • url (required): The original URL to be shortened.
  • Response:

    {
        "shortened_url": "http://localhost:8000/abc123",
        "original_url": "http://example.com",
        "created": true
    }

List Shortened URLs

  • Endpoint: GET /api/shorten/

  • Query Parameters:

    • limit (optional): Number of results per page.
    • offset (optional): Starting point for pagination.
  • Response:

    {
        "total": 1,
        "urls": [
            {
                "shortened_url": "http://localhost:8000/abc123",
                "original_url": "http://example.com"
            }
        ]
    }
    

Delete Shortened URL

  • Endpoint: DELETE /api/shorten/{key}

  • Response:

    {
        "message": "successfully deleted"
    }

Contributing

Contributions are welcome! Please open an issue or submit a pull request to the repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published