API Documentation

Authentication

Getting Started

  1. Generate an API token from your premium dashboard
  2. Include the token in your requests using the X-API-Token header
curl -H "X-API-Token: your_api_token" http://rserv.site/api/urls

Endpoints

POST /api/token

Generate a new API token for your account.

Authentication

Requires user to be logged in and have a premium account.

curl -X POST \
  http://rserv.site/api/token \
  -H 'Cookie: session=your_session_cookie'
{
  "token": "your_generated_token",
  "message": "API token generated successfully"
}
GET /api/urls

List all your shortened URLs.

Authentication

Requires API token in X-API-Token header.

curl http://rserv.site/api/urls \
  -H 'X-API-Token: your_api_token'
{
  "urls": [
    {
      "id": 1,
      "original_url": "https://example.com",
      "short_code": "abc123",
      "created_at": "2024-11-04T12:00:00",
      "clicks": 42,
      "is_custom": false
    }
  ]
}
POST /api/urls

Create a new shortened URL.

Request Parameters
  • url (required) - The URL to shorten
  • custom_alias (optional) - Custom short code for the URL
curl -X POST \
  http://rserv.site/api/urls \
  -H 'X-API-Token: your_api_token' \
  -H 'Content-Type: application/json' \
  -d '{
    "url": "https://example.com",
    "custom_alias": "my-custom-url"
  }'
{
  "message": "URL shortened successfully",
  "url": {
    "id": 1,
    "original_url": "https://example.com",
    "short_code": "my-custom-url",
    "created_at": "2024-11-04T12:00:00",
    "clicks": 0,
    "is_custom": true
  }
}
DELETE /api/urls/{url_id}

Delete a specific shortened URL.

URL Parameters
  • url_id - The ID of the URL to delete
curl -X DELETE \
  http://rserv.site/api/urls/1 \
  -H 'X-API-Token: your_api_token'
{
  "message": "URL deleted successfully"
}

Code Examples

Python

import requests

API_TOKEN = 'your_api_token'
BASE_URL = 'http://rserv.site/api'

headers = {
    'X-API-Token': API_TOKEN,
    'Content-Type': 'application/json'
}

# List all URLs
response = requests.get(f'{BASE_URL}/urls', headers=headers)
print(response.json())

# Create a shortened URL
response = requests.post(
    f'{BASE_URL}/urls',
    headers=headers,
    json={
        'url': 'https://example.com',
        'custom_alias': 'my-custom-url'
    }
)
print(response.json())

JavaScript

const API_TOKEN = 'your_api_token';
const BASE_URL = 'http://rserv.site/api';

// List all URLs
fetch(`${BASE_URL}/urls`, {
  headers: {
    'X-API-Token': API_TOKEN
  }
})
.then(response => response.json())
.then(data => console.log(data));

// Create a shortened URL
fetch(`${BASE_URL}/urls`, {
  method: 'POST',
  headers: {
    'X-API-Token': API_TOKEN,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://example.com',
    custom_alias: 'my-custom-url'
  })
})
.then(response => response.json())
.then(data => console.log(data));