shortnr

A sleek, simple, and powerful URL shortener powered by Supabase

Shortnr API Documentation

Integrate the Shortnr API into your apps to create short links and redirects instantly.


POST /api/shorten

Create a short URL.

Request:
POST https://your-domain.com/api/shorten
Content-Type: application/json

{
  "longUrl": "https://example.com",
  "customSlug": "mycustomslug"  // Optional
}
        
Response:
{
  "shortUrl": "your-domain.com/mycustomslug",
  "slug": "mycustomslug",
  "longUrl": "https://example.com"
}
        
Error Responses:
400 Bad Request      - Missing URL or slug already exists
405 Method Not Allowed
500 Internal Server Error
        

Redirect

Short URLs redirect automatically.

Visit: https://your-domain.com/mycustomslug
Redirects to: https://example.com
        

JavaScript Example

async function shortenUrl(longUrl, customSlug = '') {
  const response = await fetch('https://your-domain.com/api/shorten', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ longUrl, customSlug })
  });
  const data = await response.json();
  if (!response.ok) throw new Error(data.error || 'API error');
  return data.shortUrl;
}

// Usage
shortenUrl('https://example.com', 'example')
  .then(url => console.log('Short URL:', url))
  .catch(err => console.error(err));
        

Notes

  • Custom Slugs: Optional, auto-generated if blank.
  • Redirect: No API needed—just visit the link.
  • Rate Limits: Avoid excessive requests.