API Documentation

Complete reference guide for integrating Io URL Shortener into your applications. Enterprise-grade REST API with comprehensive authentication and rate limiting.

Getting Started

Welcome to the Io URL Shortener API! This guide will help you integrate our enterprise-grade URL shortening service into your applications.

Quick Start

To get started, you'll need to register for an account and obtain your API key. Verified users get unlimited API requests and access to custom endpoints.

Prerequisites

  • Valid email address for registration
  • Basic understanding of REST APIs
  • HTTP client (curl, Postman, or programming language HTTP library)
  • JSON parsing capabilities in your application

API Overview

REST API

Standard RESTful API with JSON responses. Supports all CRUD operations for URL management.

JWT Authentication

Secure authentication using JSON Web Tokens with access and refresh token mechanism.

Rate Limiting

Enterprise-grade rate limiting with different tiers based on user verification status.

Real-time Analytics

Comprehensive analytics with geographic data, device information, and click tracking.

Base URL

All API requests should be made to the following base URL:

https://knps.dev/api/v1/

URL Structure

API Endpoint: https://knps.dev/api/v1/{endpoint}
Short URLs: https://knps.dev/{short_code}
QR Codes: https://knps.dev/qr/{short_code}

HTTPS Required

All API calls must be made over HTTPS. HTTP requests will be rejected for security reasons.

Authentication

Io uses JWT (JSON Web Tokens) for authentication. You'll need to obtain an access token by registering and logging in through our authentication endpoints.

Token Types

Access Token

  • Used for API requests
  • Valid for 15 minutes
  • Include in Authorization header

Refresh Token

  • Used to obtain new access tokens
  • Valid for 7 days
  • Stored securely in HTTP-only cookie

Authentication Flow

1. Register Account

Create a new user account with email and password

2. Login

Authenticate with credentials to receive tokens

3. Use Access Token

Include access token in Authorization header for API calls

4. Refresh Token

Use refresh token to get new access token when expired

Authorization Header

Include your access token in the Authorization header using the Bearer scheme:

Authorization: Bearer YOUR_ACCESS_TOKEN

Example Authentication

curl -X GET "https://knps.dev/api/v1/urls" \
  -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." \
  -H "Content-Type: application/json"

Rate Limiting

Io implements enterprise-grade rate limiting to ensure fair usage and protect against abuse. Rate limits vary based on user verification status and endpoint type.

Rate Limit Tiers

Unverified Users

  • 1000 API requests per month
  • 10 URL creations per day
  • 100 analytics requests per day
  • No custom endpoints

Verified Users

  • Unlimited API requests
  • Custom endpoint access
  • Higher analytics quotas
  • Priority support

Rate Limit Headers

API responses include rate limit information in the headers:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640995200

Handling Rate Limits

When rate limit is exceeded, the API returns a 429 status code:

{
  "error": true,
  "message": "Rate limit exceeded",
  "error_code": "RATE_LIMIT_EXCEEDED",
  "retry_after": 3600
}

Error Handling

The API uses conventional HTTP response codes to indicate the success or failure of requests. Error responses include detailed information to help you debug issues.

HTTP Status Codes

200 OK - Request successful
201 Created - Resource created successfully
400 Bad Request - Invalid request parameters
401 Unauthorized - Authentication required
404 Not Found - Resource not found
429 Too Many Requests - Rate limit exceeded
500 Internal Server Error - Server error

Error Response Format

All error responses follow a consistent JSON format:

{
  "error": true,
  "message": "Validation failed",
  "error_code": "VALIDATION_ERROR",
  "errors": {
    "original_url": ["This field is required"]
  }
}

Authentication Endpoints

Authentication endpoints handle user registration, login, and token management.

POST /api/v1/auth/register

Register New User

Create a new user account with email and password.

Request Body
{
  "username": "johndoe",
  "email": "john@example.com",
  "password": "SecurePassword123!"
}
Response
{
  "success": true,
  "message": "User registered successfully",
  "data": {
    "user": {
      "id": 1,
      "username": "johndoe",
      "email": "john@example.com",
      "is_verified": false
    },
    "access_token": "eyJ0eXAiOiJKV1Q...",
    "token_type": "Bearer"
  }
}
POST /api/v1/auth/login

User Login

Authenticate user and receive access tokens.

Request Body
{
  "email": "john@example.com",
  "password": "SecurePassword123!"
}
Response
{
  "success": true,
  "message": "Login successful",
  "data": {
    "user": {
      "id": 1,
      "username": "johndoe",
      "email": "john@example.com",
      "is_verified": false
    },
    "access_token": "eyJ0eXAiOiJKV1Q...",
    "token_type": "Bearer"
  }
}
POST /api/v1/auth/refresh

Refresh Access Token

Get a new access token using refresh token.

Response
{
  "success": true,
  "data": {
    "access_token": "eyJ0eXAiOiJKV1Q...",
    "token_type": "Bearer"
  }
}

URL Management

URL management endpoints for creating, retrieving, updating, and deleting short URLs.

POST /api/v1/urls

Create Short URL

Create a new short URL with optional customization.

Request Body
{
  "original_url": "https://example.com/very-long-url",
  "custom_alias": "my-link",
  "title": "My Example Link",
  "description": "A demonstration link",
  "expires_in_days": 30
}
Response
{
  "success": true,
  "message": "URL created successfully",
  "data": {
    "id": 123,
    "original_url": "https://example.com/very-long-url",
    "short_url": "https://knps.dev/my-link",
    "short_code": "my-link",
    "title": "My Example Link",
    "qr_code_url": "https://knps.dev/qr/my-link",
    "expires_at": "2025-02-14T10:30:00Z"
  }
}
GET /api/v1/urls

List User URLs

Get paginated list of user's URLs with optional filtering.

Query Parameters
?page=1&per_page=20&search=example&status=active
Response
{
  "success": true,
  "data": {
    "urls": [
      {
        "id": 123,
        "original_url": "https://example.com",
        "short_url": "https://knps.dev/abc123",
        "short_code": "abc123",
        "clicks": 42,
        "created_at": "2025-01-14T10:30:00Z"
      }
    ],
    "pagination": {
      "page": 1,
      "per_page": 20,
      "total": 100,
      "pages": 5
    }
  }
}

Analytics

Analytics endpoints provide comprehensive click tracking and reporting data.

GET /api/v1/analytics/{url_id}

Get URL Analytics

Retrieve detailed analytics for a specific URL.

Query Parameters
?days=30
Response
{
  "success": true,
  "data": {
    "total_clicks": 1250,
    "unique_clicks": 890,
    "daily_clicks": [
      {"date": "2025-01-14", "clicks": 42},
      {"date": "2025-01-13", "clicks": 38}
    ],
    "top_countries": [
      {"country": "United States", "clicks": 450},
      {"country": "United Kingdom", "clicks": 200}
    ],
    "device_breakdown": {
      "desktop": 60,
      "mobile": 35,
      "tablet": 5
    }
  }
}

Public APIs

Public endpoints that don't require authentication for basic functionality.

POST /api/v1/public/shorten

Create Temporary URL

Create a temporary URL that expires in 15 minutes (no auth required).

Request Body
{
  "original_url": "https://example.com"
}
Response
{
  "success": true,
  "message": "Temporary URL created successfully",
  "data": {
    "original_url": "https://example.com",
    "short_url": "https://knps.dev/temp123",
    "short_code": "temp123",
    "expires_at": "2025-01-14T11:45:00Z",
    "qr_code_url": "https://knps.dev/api/v1/public/qr/temp123"
  }
}

Code Examples

Practical examples for common use cases and integration patterns.

API Key Authentication Example

Simple script to test API key authentication for URL creation.

"""
Test script for API key authentication in the Io URL Shortener.
"""

import requests
import sys

def test_api_key_auth(api_key):
    """Test API key authentication for URL creation."""
    base_url = "http://knps.dev/api/v1"
    session = requests.Session()
    
    # Set API key in headers
    session.headers.update({
        'Content-Type': 'application/json',
        'X-API-Key': api_key
    })
    
    # Try creating a URL with API key
    print(f"Testing URL creation with API key: {api_key[:10]}...")
    response = session.post(
        f"{base_url}/urls",
        json={
            "original_url": "https://github.com/KanopusDev/Kale",
            "title": "API Key Test"
        }
    )
    
    print(f"Status code: {response.status_code}")
    
    if response.status_code in (200, 201):
        data = response.json()['data']
        print("URL created successfully with API key!")
        print(f"Original URL: {data['original_url']}")
        print(f"Short URL: {data['short_url']}")
        print(f"Short code: {data['short_code']}")
        return True
    else:
        print("Failed to create URL with API key.")
        print(f"Response: {response.text}")
        return False

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python test_api_key.py <api_key>")
        sys.exit(1)
    
    api_key = sys.argv[1]
    test_api_key_auth(api_key)

Usage: python test_api_key.py YOUR_API_KEY

cURL Examples

Create URL with API Key
curl -X POST "https://knps.dev/api/v1/urls" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "original_url": "https://example.com",
    "title": "API Key Test"
  }'
Get Analytics
curl -X GET "https://knps.dev/api/v1/analytics/123?days=30" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Changelog

Track the latest updates and improvements to the Io API.

Version 1.0.0

August 14, 2025
✨ New Features
  • Complete REST API with authentication
  • URL shortening with custom aliases
  • Comprehensive analytics and reporting
  • QR code generation
  • Rate limiting and security features
  • Admin dashboard and user management
  • Public API for temporary URLs
🔧 Technical
  • JWT authentication with refresh tokens
  • SQLite database with WAL mode
  • Enterprise-grade security headers
  • Comprehensive error handling
  • API versioning and documentation