Page cover

terminalURL Shortening API Documentation

Overview

The URL Shortening API enables authenticated users to convert long URLs into short, user-friendly links. It includes built-in rate limiting (100 requests per 24 hours per API key) and error handling to ensure smooth integration into your applications.

Base Production URL:

https://4n.eco

Authentication

All API requests must be authenticated using a valid API key.

  • Header Name: x-api-key

  • Header Value: Your API key (e.g., <YOUR_API_KEY>)

Keep your API key secure and do not expose it publicly.

Endpoint

GET /api/shorten-public

This endpoint shortens a provided URL. You may supply an optional custom alias; if omitted, an alias will be automatically generated.

Query Parameters

  • originalUrl (required) The long URL that you wish to shorten.

  • alias (optional) A custom alias for the shortened URL. Note: If the alias is already in use, the API returns an error.

Request Examples

1. Using a Custom Alias

cURL (Single Line - Windows/Unix):

Expected Response (HTTP 200):

2. Using an Auto-Generated Alias

cURL:

Expected Response (HTTP 200):

Error Responses

  • Missing Required Parameter (originalUrl):

    Response:

    HTTP Status: 400

  • Alias Already in Use:

    Response:

    HTTP Status: 409

  • Invalid API Key:

    Response:

    HTTP Status: 401

  • Rate Limit Exceeded:

    Response:

    HTTP Status: 429

Testing Scenarios

Below are sample cURL commands for testing various scenarios. Replace <YOUR_API_KEY> with your actual API key when testing.

Valid Request with a Custom Alias

Valid Request Without Providing an Alias

Missing Required Parameter (originalUrl)

Alias Already in Use

Step 1: Create a shortened URL

Step 2: Attempt to use the same alias again

Invalid API Key

Rate Limiting (Optional Test)

Run this command repeatedly to simulate exceeding 100 requests in 24 hours:

Integration Examples

JavaScript (Using Fetch)

Integrate the API directly in your web application with a simple fetch request:

Python (Using Requests)

Use Python's requests library to integrate the API into your backend application:

Integration Notes

  • Error Handling: Check the HTTP status code and error messages in your integration code to handle errors gracefully.

  • Security: Never expose your API key in publicly accessible code. Use environment variables or secure storage.

  • Rate Limits: If your application might exceed 100 requests per day, implement retry logic or notify users of the limit.

  • Custom vs. Auto-Generated Alias: If you don’t require a specific alias, omitting the alias parameter allows the API to generate one automatically.

Conclusion

The URL Shortening API provides a straightforward and secure method to generate short URLs. With detailed error responses, built-in rate limiting, and flexible aliasing, developers can easily integrate this service into web or backend applications. For further assistance or to report issues, please contact our support team.

Last updated