Skip to content

Random-Projects9/url-shortner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener

A simple URL shortener API built with FastAPI and Python. It generates short codes for long URLs, stores them in a JSON file, and allows redirection, listing, and deletion of short URLs.

Features

  • Shorten long URLs to 6-character codes
  • Redirect to the original URL using the short code
  • List all stored short URLs
  • Delete a short URL

Requirements

  • Python 3.7+
  • FastAPI
  • Uvicorn
  • pydantic

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/url-shortener.git
    cd url-shortener
  2. Install dependencies:

    pip install fastapi uvicorn pydantic

Usage

Start the FastAPI server:

uvicorn url_shortner:app --reload

API Endpoints

  • POST /shorten
    Shorten a URL.
    Request body (JSON):

    {
      "original_url": "https://example.com"
    }

    Response:

    {
      "short_url": "abc123"
    }
  • GET /{short_code}
    Redirects to the original URL.

  • GET /urls/list
    Returns all short codes and their original URLs.

  • DELETE /urls/{short_code}
    Deletes a short URL.

Data Storage

Short URLs are stored in url_storage.json in the project directory.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages