📘 Dokumentasi API - Shtl.PW

Beranda

📌 API Endpoint

https://shtl.pw/api?url=URL_TARGET

Ganti URL_TARGET dengan tautan panjang yang ingin Anda pendekkan.

▶️ Contoh Permintaan

https://shtl.pw/api?url=https://www.google.com/maps/place/Statue+of+Liberty/@40.6892534,-74.0466891,17z/data=!3m1!4b1!4m5!3m4!1s0x0:0x123456789abcdef!8m2!3d40.6892534!4d-74.0445002

📄 Contoh Respons JSON

{
  "status": "success",
  "original_url": "https://www.google.com/maps/place/Statue+of+Liberty/@40.6892534,-74.0466891,17z/data=!3m1!4b1!4m5!3m4!1s0x0:0x123456789abcdef!8m2!3d40.6892534!4d-74.0445002",
  "short_url": "https://shtl.pw/s=e1cd19"
}
      

💻 Penggunaan dengan JavaScript (Fetch)

// URL yang ingin dipendekkan
const url = "https://www.google.com/maps/place/Statue+of+Liberty/@40.6892534,-74.0466891,17z/data=!3m1!4b1!4m5!3m4!1s0x0:0x123456789abcdef!8m2!3d40.6892534!4d-74.0445002";
const apiUrl = "https://shtl.pw/api?url=" + encodeURIComponent(url);

fetch(apiUrl)
  .then(response => response.json())
  .then(data => {
    if (data.status === "success") {
      console.log("Short URL:", data.short_url);
    }
  })
  .catch(error => console.error(error));
      

📝 Penggunaan dengan Form HTML

<form id="shortForm">
  <input type="url" id="urlInput" required>
  <button type="submit">Shorten URL</button>
</form>

<script>
document.getElementById('shortForm').addEventListener('submit', function(e) {
  e.preventDefault();
  const originalUrl = document.getElementById('urlInput').value;
  const apiUrl = 'https://shtl.pw/api?url=' + encodeURIComponent(originalUrl);

  fetch(apiUrl)
    .then(response => response.json())
    .then(data => {
      if (data.status === 'success') {
        alert('Short URL: ' + data.short_url);
      }
    });
});
</script>