Skip to content

MacWeTT/SwiftBit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple URL shortening service built on FastAPI.

SwiftBit

Tech Stack Used

Overview & Logic

This service provides functionality to shorten long URLs into shorter, more manageable links. Users can create shortened URLs, retrieve them, and delete them as needed.

A random short UUID is generated for a request object. When the shortened URL is used in the browser, the API request is called to search for the requested URL. If found, the user is redirected to the original URL, otherwise a 404 response is returned.

Base URL

The base URL for accessing the service endpoints is https://swiftbit.onrender.com .

You can also access the API Docs on /docs powered by SwaggerUI or on /redoc powered by ReDoc.

Authentication

Authentication is required for creating and managing urls to ensure the security of user data. Authentication tokens must be included in the request headers for these endpoints.

Authentication Endpoints

  • URL: /user/register
  • Method: POST
  • Description: Register your user to start using the service.

  • URL: /user/login
  • Method: POST
  • Description: Login a user so that URLs can be managed.

  • URL: /user/edit-user
  • Method: PATCH
  • Description: Edit the details of the logged in user.

  • URL: /user/delete-user
  • Method: DELETE
  • Description: Deletes the logged in user from the database.

Service Endpoints and Usage

Get User URLs

  • URL: /url
  • Method: GET
  • Description: Fetch all the shortened urls of the user who raised the request.
  • Response Body:
    [
      {
        "short_url": "https://swiftbit.onrender.com/df200df7",
        "url": "https://leetcode.com/MacWeTT/"
      },
      {
        "short_url": "https://swiftbit.onrender.com/175a872c",
        "url": "https://www.ign.com/wikis/red-dead-redemption-2/Walkthrough"
      }
    ]

Create Short URL

  • URL: /url
  • Method: POST
  • Description: Accepts a request url and returns a shortened URL..
  • Request Body:
    {
      "request_url": "string"
    }
  • Response Body:
    {
      "message": "Requested URL has been shortened.",
      "original_url": "https://www.ign.com/wikis/red-dead-redemption-2/Walkthrough",
      "shortened_url": "https://swiftbit.onrender.com/99d72426"
    }

Delete URL

  • URL: /url/{url_id}
  • Method: DELETE
  • Description: Fetch all the shortened urls of the user who raised the request.
  • Request Body:
    {
      "url_id": "df200df7"
    }
  • Response Body:
    {
      "message": "Short URL has been deleted successfully."
    }

Installation and Setup

1. Install Python

Ensure you have Python installed on your system. You can download it from the official Python website and follow the installation instructions for your operating system.

2. Create a Virtual Environment (Optional but Recommended)

It's a good practice to work within a virtual environment to isolate your project dependencies. You can create a virtual environment using venv or virtualenv. For example:

# Using venv (Python 3.3+)
python3 -m venv myenv
source myenv/bin/activate

# Using virtualenv
virtualenv myenv
source myenv/bin/activate

Your console should look like this:

(env) macwett@MacWeTT-PC:~/SwiftBit$

If it doesn't, make sure you have installed and activated the virtual environment correctly.

3. Install Required Dependencies

Next, install the required dependencies by using this command.
Make sure your virtual environment is activated before installing the dependencies.

pip install -r requirements.txt

4. Initialize Environment Variables

Next, create a .env file in the root directory and add the following keys to it:

API_URL="http://localhost:8000"
ALGORITHM = "YOUR_JWT_ALGORITHM"
SECRET_KEY = "YOUR_SECRET_KEY"

If you don't have a secret key, you can generate one for yourself using a script provided with the application and input that here.

5. Run the application

Finally, run the application by using this command:

uvicorn main:app --reload

This will run the uvicorn server on port 8000, given everything is set up flawlessly :)