API Website URL Shortener - Panduan Penggunaan


1. URL Shortening

Endpoint: GET /shorten

Parameter:

  • url (required): The URL you want to shorten.
  • customid (optional): Custom short ID for the shortened URL.

Example:

plaintext

GET /shorten?url=https://www.example.com&customid=mycustomid

Response:

json

{
  "status": true,
  "creator": "akuari.my.id",
  "url": "https://www.example.com",
  "shortenedUrl": "https:///mycustomid",
  "deleteUrl": "https:///mycustomid/<key>"
}
                                      

2. Redirect to Original URL

Endpoint: GET /:shortid

Example:

plaintext

GET /mycustomid

If the short ID exists, it will redirect to the original URL.

3. Delete Shortened URL

Endpoint: GET /:shortid/:key

If you want to get a JSON response, set the header 'Accept': 'application/json'

Axios Example:

const axiosExample = async () => {
    try {
        const response = await axios.get('https:///mycustomid/<key>', {
            headers: {
                'Accept': 'application/json',
            }
        });
        console.log(response.data);
    } catch (error) {
        console.error('Error:', error);
    }
};

axiosExample();

Fetch Example:

const fetchExample = async () => {
    try {
        const response = await fetch('https:///mycustomid/<key>', {
            method: 'GET',
            headers: {
                'Accept': 'application/json',
            },
        });
        const data = await response.json();
        console.log(data);
    } catch (error) {
        console.error('Error:', error);
    }
};

fetchExample();
                                      

Example:

plaintext

GET /mycustomid/<key>

Response:

json

{
    "message": "Short URL deleted successfully"
}
                                      

Important Notes:

  • Custom ID is optional. If not provided, a random short ID will be generated.
  • The 'deleteUrl' in the response from the shorten endpoint provides the URL to delete the shortened URL. Use with caution as it requires the correct key.
Visitor Views
Load Server
Status Server
UP