API Documentation

The simplest URL shortener API. No authentication. No keys. Just free.

Forever Free 60 requests/minute

Getting Started

4Lin.UK provides a simple JSON API for shortening URLs. No registration, no API keys, no complex authentication. Just send a request and get your short URL.

Base URL

https://4lin.uk/api.php

All endpoints use this base URL with the action parameter.

Quick Start (GET for testing)

For quick testing, you can shorten a URL using a simple GET request:

https://4lin.uk/api.php?action=shorten&url=https://example.com

For production use, POST JSON is recommended (see examples below).

Rate Limiting

Fair Use Policy

  • 60 requests per minute per IP/session
  • No API keys - completely open
  • 429 Too Many Requests response when exceeded

Rate Limit Headers (when available)

X-RateLimit-Limit: 60 X-RateLimit-Remaining: 58 X-RateLimit-Reset: 1623456789

API Endpoints

GET ?action=info

Get API information, version, and available endpoints.

Response

{ "success": true, "service": "4Lin.UK URL Shortener", "version": "1.0", "rate_limit": "60 requests per minute", "endpoints": { "GET ?action=info": "API information", "GET ?action=stats": "Service statistics", "GET ?action=clicks&code={code}": "Get click count", "GET ?action=qr&code={code}": "Get QR code", "GET/POST ?action=shorten": "Create short URL" } }
GET ?action=stats

Get global service statistics.

Response

{ "success": true, "stats": { "total_urls_shortened": 12345, "total_clicks": 678901, "service_status": "operational", "rate_limit": "60/minute" } }
POST ?action=shorten

Create a shortened URL. Returns existing short code if the URL already exists.
Tip: You can also use GET for quick testing (see Getting Started).

Request Parameters

Parameter Type Required Description
url string Yes The URL to shorten (http:// or https://)

Example Request (POST JSON)

POST /api.php?action=shorten HTTP/1.1 Host: 4lin.uk Content-Type: application/json { "url": "https://example.com/very/long/url" }

Success Response

{ "success": true, "short_code": "aB3xY7", "short_url": "https://4lin.uk/aB3xY7", "original_url": "https://example.com/very/long/url", "is_new": true }
GET ?action=clicks&code={code}

Get the number of clicks for a specific short URL.

Parameter Type Required Description
code string Yes The short code (e.g., aB3xY7)

Response

{ "success": true, "short_code": "aB3xY7", "short_url": "https://4lin.uk/aB3xY7", "clicks": 42 }
GET ?action=qr&code={code}

Get a QR code URL for a short link.

Parameter Type Required Description
code string Yes The short code (e.g., aB3xY7)
size int Optional QR code size in pixels (default: 200)

Response

{ "success": true, "short_code": "aB3xY7", "short_url": "https://4lin.uk/aB3xY7", "qr_code_url": "https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https%3A%2F%2F4lin.uk%2FaB3xY7", "qr_code_html": "<img src="https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https%3A%2F%2F4lin.uk%2FaB3xY7" alt="QR Code" width="200" height="200">" }
Example QR Code

Example QR Code for https://4lin.uk/aB3xY7

Code Examples

JavaScript

// Shorten a URL using fetch async function shortenUrl(url) { const response = await fetch('https://4lin.uk/api.php?action=shorten', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url }) }); const data = await response.json(); if (data.success) { console.log('Short URL:', data.short_url); console.log('QR Code:', data.qr_code_url); } return data; } // Example usage shortenUrl('https://example.com').then(console.log); // Get click count async function getClicks(shortCode) { const response = await fetch(`https://4lin.uk/api.php?action=clicks&code=${shortCode}`); const data = await response.json(); return data.clicks; } // Get QR code URL function getQRCode(shortCode, size = 200) { return `https://4lin.uk/api.php?action=qr&code=${shortCode}&size=${size}`; }

Python

import requests def shorten_url(url): response = requests.post( 'https://4lin.uk/api.php?action=shorten', json={'url': url} ) return response.json() def get_clicks(short_code): response = requests.get( f'https://4lin.uk/api.php?action=clicks&code={short_code}' ) data = response.json() return data.get('clicks', 0) def get_qr_code(short_code, size=200): return f'https://4lin.uk/api.php?action=qr&code={short_code}&size={size}' # Example usage result = shorten_url('https://example.com') print("Short URL:", result.get('short_url')) print("QR Code:", result.get('qr_code_url')) clicks = get_clicks(result.get('short_code', '')) print("Clicks:", clicks)

PHP

<?php function shortenUrl($url) { $ch = curl_init('https://4lin.uk/api.php?action=shorten'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['url' => $url])); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); $response = curl_exec($ch); curl_close($ch); return json_decode($response, true); } function getClicks($shortCode) { $response = file_get_contents("https://4lin.uk/api.php?action=clicks&code={$shortCode}"); $data = json_decode($response, true); return $data['clicks'] ?? 0; } // Example usage $result = shortenUrl('https://example.com'); echo "Short URL: " . ($result['short_url'] ?? '') . PHP_EOL; echo "QR Code: " . ($result['qr_code_url'] ?? '') . PHP_EOL; ?>

cURL

# Shorten a URL (POST JSON) curl -X POST "https://4lin.uk/api.php?action=shorten" \ -H "Content-Type: application/json" \ -d '{"url":"https://example.com"}' # Shorten a URL (GET quick test) curl "https://4lin.uk/api.php?action=shorten&url=https://example.com" # Get click count curl "https://4lin.uk/api.php?action=clicks&code=aB3xY7" # Get QR code URL curl "https://4lin.uk/api.php?action=qr&code=aB3xY7&size=200" # Get API info curl "https://4lin.uk/api.php?action=info" # Get service stats curl "https://4lin.uk/api.php?action=stats"

Response Formats

Success Response

Successful responses include "success": true.
{ "success": true, "short_code": "aB3xY7", "short_url": "https://4lin.uk/aB3xY7", "original_url": "https://example.com", "is_new": true }

Existing URL Response

If a URL has already been shortened, the API returns the existing short code.

{ "success": true, "short_code": "aB3xY7", "short_url": "https://4lin.uk/aB3xY7", "original_url": "https://example.com", "is_new": false }

Error Codes

Errors return an appropriate HTTP status code and a JSON body containing an error message. (Some errors may also include extra fields like message and retry_after.)

Status Code Error Description Solution
400 Missing URL No URL provided Add the url parameter to the request
400 Invalid URL format URL is malformed Ensure it includes http:// or https://
404 Short code not found The short code doesn't exist Check the short code and try again
404 Unknown action Invalid API endpoint Check the action parameter
429 Rate limit exceeded Too many requests Wait and retry after the value in retry_after (seconds)
405 Method not allowed Wrong HTTP method Use GET/POST as specified
500 Server error Internal error Try again later

Error Response Examples

400 Bad Request
{ "error": "Invalid URL format" }
429 Too Many Requests
{ "error": "Rate limit exceeded", "message": "Maximum 60 requests per minute", "retry_after": 60 }

Frequently Asked Questions

❓ Do I need an API key?

No. The 4Lin.UK API is completely free and open. No registration, no keys, no authentication required.

❓ What are the rate limits?

60 requests per minute per IP/session to ensure fair usage for all developers.

❓ Are links permanent?

Links don’t expire by default. We may remove links that violate our Terms (malware/phishing/illegal content) or are abusive.

❓ Can I use custom short codes?

Currently, the API generates random short codes. Custom aliases are coming soon.

❓ What's the maximum URL length?

There’s no enforced limit, but URLs longer than 2000 characters may cause issues with some browsers.

❓ Is HTTPS required?

We recommend including the full URL with protocol. If your API auto-adds HTTPS when missing, document that behavior here.

❓ Can I use this commercially?

Yes. The API is free for personal and commercial use. No attribution required.