Skip to main content

Short-URL API Documentation

Build powerful URL shortening features into your applications with our secure, FastAPI-based REST API. Complete with JWT authentication, password protection, and comprehensive URL management.

Quick Start

Get your URL shortener up and running in minutes

1

Install Dependencies

Clone the repository and install the required Python packages.
git clone https://github.com/Tanmandal/Short-URL.git
cd Short-URL
pip install -r requirements.txt
2

Configure Environment

Set up your environment variables for MongoDB connection and authentication.
export MONGO_URI="mongodb://localhost:27017"
export SECRET_KEY="your-secret-key-here"
export TOKEN_EXPIRE="5"
export SURL_BASE="http://127.0.0.1:8000"
3

Start the Server

Launch the FastAPI application with Uvicorn.
uvicorn main:app --reload
Your API will be available at http://127.0.0.1:8000
4

Create Your First Short URL

Use the /create endpoint to generate a short URL.
curl -X POST "http://127.0.0.1:8000/create" \
  -H "Content-Type: application/json" \
  -d '{
    "url_code": "mylink",
    "url_pass": "secret123",
    "url": "https://example.com"
  }'
{
  "message": "URL created",
  "short_url": "http://127.0.0.1:8000/mylink"
}

Key Features

Everything you need to build a production-ready URL shortening service

JWT Authentication

Secure token-based authentication with automatic token refresh and validation endpoints

Password Protection

Optional password protection for short URLs with bcrypt hashing

URL Management

Pause, resume, delete, and modify URLs with full control over your links

Analytics Tracking

Built-in hit counter tracking with resettable statistics

MongoDB Integration

Reliable data persistence with MongoDB and async Motor driver

CORS Support

Configurable CORS middleware for cross-origin API access

Explore by Topic

Deep dive into specific areas of the API

Authentication

Learn about JWT tokens, login flows, and token management

Public Endpoints

Create URLs, authenticate, and access health checks

Protected Endpoints

Manage URLs with secure, authenticated operations

Data Models

Understand request and response schemas

Configuration

Configure your deployment with environment variables

Environment Setup

Set up MongoDB, secrets, and runtime settings

Ready to get started?

Follow our quickstart guide to create your first short URL in under 5 minutes, or explore the complete API reference for advanced features.