tshortly.sbs API Documentation

API Overview

The tshortly.sbs API is a free, RESTful service designed to shorten URLs efficiently without requiring authentication. Developed by Tajammal Technovates, it supports URLs with or without protocols and normalizes them to HTTPS for secure redirection. Ideal for link management in websites, apps, or campaigns, with plans for future features like analytics.

  • Base URL: https://tshortly.sbs
  • Key Features: No API key needed, fast redirection, scalable design.
  • Limitations: No custom aliases or analytics yet (coming soon).
Endpoint Details
Request Method: GET
https://tshortly.sbs/api/handler.php?url=$url

Use this endpoint to shorten a URL. Example requests:

  • With protocol: https://tshortly.sbs/api/handler.php?url=https://example.com
  • Without protocol: https://tshortly.sbs/api/handler.php?url=example.com

Notes: URLs are normalized to HTTPS if no protocol is provided. Response is in JSON format.

Parameters

Parameters:

url

- The long URL to shorten (required, e.g., https://example.com or example.com).

Validation: The API checks for valid URL formats. Invalid formats return an error.

Response Formats

Examples:

Success Response

{
    "short_url": "https://tshortly.sbs/r59aQ",
    "status": "success"
}

Error Response (No URL)

{
    "error": "No URL provided",
    "status": "error"
}

Error Response (Invalid URL)

{
    "error": "Invalid URL provided",
    "status": "error"
}

Notes: All responses are in JSON. `short_url` is returned on success; `error` and `status` are returned on failure.

Error Handling

Possible Errors:

No URL provided

- Missing `url` parameter.

Invalid URL provided

- Malformed URL format.

DATABASE_ERROR

- Internal server issue (retry or contact support).

Recommendation: Check the `status` field. Use try-catch for network errors and log `error` messages for debugging.

Code Examples

PHP

Error: 

Python

import requests
import json

long_url = 'https://example.com'
api_url = "https://tshortly.sbs/api/handler.php?url=" + long_url

try:
    response = requests.get(api_url)
    data = response.json()
    if data.get('status') == 'success':
        print(f"Shortened URL: {data['short_url']}")
    else:
        print(f"Error: {data['error']}")
except Exception as e:
    print(f"Request failed: {e}")

Node.js

const https = require('https');
const url = require('url');

const longUrl = 'https://example.com';
const apiUrl = "https://tshortly.sbs/api/handler.php?url=" + encodeURIComponent(longUrl);

https.get(apiUrl, (res) => {
    let data = '';
    res.on('data', (chunk) => { data += chunk; });
    res.on('end', () => {
        const parsedData = JSON.parse(data);
        if (parsedData.status === 'success') {
            console.log(`Shortened URL: ${parsedData.short_url}`);
        } else {
            console.log(`Error: ${parsedData.error}`);
        }
    });
}).on('error', (e) => {
    console.error(`Request failed: ${e.message}`);
});

Java

import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.json.JSONObject;

public class UrlShortener {
    public static void main(String[] args) {
        String longUrl = "https://example.com";
        try {
            String apiUrlStr = "https://tshortly.sbs/api/handler.php?url=" + java.net.URLEncoder.encode(longUrl, "UTF-8");
            URL apiUrl = new URL(apiUrlStr);
            HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection();
            conn.setRequestMethod("GET");

            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String inputLine;
            StringBuffer content = new StringBuffer();
            while ((inputLine = in.readLine()) != null) {
                content.append(inputLine);
            }
            in.close();

            JSONObject data = new JSONObject(content.toString());
            if (data.getString("status").equals("success")) {
                System.out.println("Shortened URL: " + data.getString("short_url"));
            } else {
                System.out.println("Error: " + data.getString("error"));
            }
        } catch (Exception e) {
            System.out.println("Request failed: " + e.getMessage());
        }
    }
}
Best Practices
  • URL Encoding: Always encode the `url` parameter to handle special characters.
  • HTTPS Only: Use HTTPS for all requests to ensure security.
  • Retry Logic: Implement retries for transient errors like network issues.
  • Validation: Validate URLs client-side before sending to reduce API calls.
  • Caching: Cache shortened URLs locally if reusing them frequently.
  • Monitoring: Log errors and monitor response times.
  • Rate Limits: Currently unlimited, but prepare for future quotas with delays if needed.
Advanced Features
  • Batch Shortening: Not supported yet; send individual requests.
  • Custom Domains: Planned for future releases.
  • Analytics: Coming soon (track clicks, etc.).
  • Integration Ideas: Embed in social media apps, email campaigns, or CMS plugins.
FAQs
  • Is the API free? Yes, completely free with no signup required.
  • What if the URL is already shortened? A new short code is generated.
  • How long do shortened URLs last? Indefinitely, unless abused.
  • Can I delete a shortened URL? Not currently; contact support for issues.
  • Supported Protocols? HTTP/HTTPS; others may fail.
  • Max URL Length? Up to 2048 characters.
Contact Support

For questions, bugs, or feature requests:

TShortly - Free URL Shortener