Slugify API: Complete Developer Guide

Need to create clean, SEO-friendly URLs? This guide covers everything about slug generation via API, including what makes a good slug, SEO benefits, and implementation examples in multiple programming languages.

What is a URL Slug?

A URL slug is the part of a URL that identifies a page in a readable format. It's typically derived from the page title, with spaces replaced by hyphens and special characters removed.

Example: Hello World! How Are You? becomes hello-world-how-are-you

SEO Benefits of Slugs

Good slugs improve search engine optimization:

Readability

Users can understand the page content from the URL alone, improving click-through rates.

Keywords

Including relevant keywords in slugs can help with search rankings.

Shareability

Clean URLs are more likely to be shared on social media and other platforms.

SEO Tip: Keep slugs short (3-5 words), use hyphens as separators, and include your primary keyword for best results.

Using the Slugify API

TinyFn provides a simple endpoint to generate URL slugs:

API Request
POST https://api.tinyfn.io/v1/text/slugify
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "text": "Hello World! How Are You?"
}
Response
{
  "slug": "hello-world-how-are-you",
  "original": "Hello World! How Are You?"
}

Parameters

Parameter Type Description
text string The text to convert to a slug (required)
separator string Character to use as separator (default: -)
lowercase boolean Convert to lowercase (default: true)
max_length integer Maximum slug length (optional)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/text/slugify',
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'your-api-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ text: 'My Blog Post Title!' })
  }
);
const { slug } = await response.json();
console.log(slug); // my-blog-post-title

Python

import requests

response = requests.post(
    'https://api.tinyfn.io/v1/text/slugify',
    headers={'X-API-Key': 'your-api-key'},
    json={'text': 'My Blog Post Title!'}
)
slug = response.json()['slug']
print(slug)  # my-blog-post-title

cURL

curl -X POST "https://api.tinyfn.io/v1/text/slugify" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"text": "My Blog Post Title!"}'

Common Use Cases

  • Blog Posts: Generate URLs from article titles
  • E-commerce: Create product URLs from product names
  • User Content: Generate clean URLs for user-generated content
  • Categories: Create category and tag URLs
  • File Names: Generate safe file names from user input

Best Practices

  1. Keep it short: Aim for 3-5 words maximum
  2. Use hyphens: Hyphens are preferred over underscores for SEO
  3. Remove stop words: Consider removing a, the, and, etc.
  4. Handle duplicates: Append numbers to handle duplicate slugs
  5. Lowercase only: Use lowercase for consistency

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "tinyfn-text": {
      "url": "https://api.tinyfn.io/mcp/text/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

See all text analysis tools available via MCP in our Text Analysis MCP Tools for AI Agents guide.

Try the Slugify API

Get your free API key and start generating slugs in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key