← Kembali ke Shortku

📖 Dokumentasi API

Integrasikan Shortku ke aplikasi Anda

Base URL

https://s.zetri.my.id

1. Perpendek URL

Mengubah URL panjang menjadi short URL.

POST /api/shorten

Request Body

FieldTipeWajibDeskripsi
urlstringURL panjang yang ingin diperpendek

Contoh Request

curl -X POST https://s.zetri.my.id/api/shorten 
  -H "Content-Type: application/json" 
  -d '{"url":"https://example.com/sangat/panjang"}'

Response Sukses (200)

{
  "shortUrl": "https://s.zetri.my.id/abc123",
  "code": "abc123",
  "originalUrl": "https://example.com/sangat/panjang"
}

Error Response

StatusKondisi
400URL tidak disertakan
400Format URL tidak valid
400URL terlalu panjang (>2048 karakter)
500Internal server error

2. Redirect

Akses short URL — otomatis redirect ke URL asli.

GET /:code
# Buka di browser:
https://s.zetri.my.id/abc123

# Akan 301 redirect ke:
# https://example.com/sangat/panjang

3. Statistik

Lihat jumlah klik dan metadata short URL.

GET /api/stats/:code

Response (200)

{
  "code": "abc123",
  "original_url": "https://example.com/sangat/panjang",
  "clicks": 42,
  "created_at": "2026-06-16 04:15:12",
  "updated_at": "2026-06-16 04:20:30"
}

Error (404)

{ "error": "Code not found" }

💻 Contoh Kode

Python

import requests

# Shorten
resp = requests.post("https://s.zetri.my.id/api/shorten", json={
    "url": "https://example.com/link-panjang"
})
data = resp.json()
print("Short URL:", data["shortUrl"])
print("Code:", data["code"])

# Stats
stats = requests.get(
    f"https://s.zetri.my.id/api/stats/{data['code']}"
).json()
print("Clicks:", stats["clicks"])

JavaScript (Fetch)

// Shorten URL
async function shorten(url) {
  const res = await fetch("https://s.zetri.my.id/api/shorten", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ url })
  });
  const data = await res.json();
  return data;
}

// Pakai
shorten("https://example.com").then(d => {
  console.log("Short URL:", d.shortUrl);
});

Node.js (Axios)

import axios from "axios";

// Shorten
const { data } = await axios.post(
  "https://s.zetri.my.id/api/shorten",
  { url: "https://example.com" }
);
console.log(data.shortUrl);

// Stats
const { data: stats } = await axios.get(
  `https://s.zetri.my.id/api/stats/${data.code}`
);
console.log(`${stats.clicks} clicks`);

PHP

$ch = curl_init("https://s.zetri.my.id/api/shorten");
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
  CURLOPT_POSTFIELDS => json_encode([
    "url" => "https://example.com"
  ]),
  CURLOPT_RETURNTRANSFER => true
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);

echo "Short URL: " . $data["shortUrl"];

Go

package main

import (
  "bytes"
  "encoding/json"
  "fmt"
  "net/http"
)

func main() {
  body, _ := json.Marshal(map[string]string{
    "url": "https://example.com",
  })

  resp, _ := http.Post(
    "https://s.zetri.my.id/api/shorten",
    "application/json",
    bytes.NewBuffer(body),
  )

  var result struct {
    ShortUrl string `json:"shortUrl"`
    Code     string `json:"code"`
  }
  json.NewDecoder(resp.Body).Decode(&result)
  resp.Body.Close()

  fmt.Println("Short URL:", result.ShortUrl)
}

📋 Aturan

AturanNilai
Maks. panjang URL2048 karakter
Panjang short code6 karakter
Rate limit10 req/detik per IP
HTTPSWajib (HTTP otomatis redirect)
Masa berlakuPermanent