URL Shortener API Documentation

Introduction

This API allows you to create short URLs programmatically. All URLs created through this API will expire after one month of inactivity. Each visit to a short URL will reset its expiration time for another month.

Base URL

https://shortenurl.app

Endpoints

Create Short URL

POST /api/v1/shorten

Request Headers

Content-Type: application/json

Request Body

{
  "url": "https://example.com"
}

Success Response (200 OK)

{
  "success": true,
  "data": {
    "originalUrl": "https://example.com",
    "shortUrl": "https://shortenurl.app/abc123",
    "shortCode": "abc123",
    "expiresAt": "2024-02-17T12:00:00.000Z"
  }
}

Error Response (400 Bad Request)

{
  "error": "Invalid URL",
  "example": {
    "url": "https://example.com"
  }
}

Example Request (cURL)

curl -X POST "https://shortenurl.app/api/v1/shorten" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}'

Example Request (JavaScript)

const response = await fetch("https://shortenurl.app/api/v1/shorten", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    url: "https://example.com"
  })
});

const data = await response.json();

Important Notes

  • All URLs expire after one month of inactivity
  • Visiting a short URL resets its expiration time
  • Invalid URLs will result in a 400 Bad Request response
  • The API only accepts JSON requests

Rate Limiting

Currently, there are no rate limits in place. However, we recommend implementing your own rate limiting in production environments to prevent abuse.