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.
https://tshortly.sbs/api/handler.php?url=$url
Use this endpoint to shorten a URL. Example requests:
https://tshortly.sbs/api/handler.php?url=https://example.comhttps://tshortly.sbs/api/handler.php?url=example.comNotes: URLs are normalized to HTTPS if no protocol is provided. Response is in JSON format.
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.
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.
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.
Error:
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}")
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}`);
});
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());
}
}
}
For questions, bugs, or feature requests: