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.
- 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
- Python 3.7+
- FastAPI
- Uvicorn
- pydantic
-
Clone the repository:
git clone https://github.com/yourusername/url-shortener.git cd url-shortener -
Install dependencies:
pip install fastapi uvicorn pydantic
Start the FastAPI server:
uvicorn url_shortner:app --reload-
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.
Short URLs are stored in url_storage.json in the project directory.