Gen-Endpoint
Back to API List
URL Shortener API
Create, manage, and get stats for shortened URLs. Includes a redirector endpoint.
Utilities
Internal API - Hosted by this App
API Endpoints & Usage
Explore and interact with the available endpoints for the URL Shortener API. These API routes are live! The paths shown below are relative to your application's base URL. For example, if this application is hosted at https://gen-endpoint.com, an endpoint path for this API, such as /api/shorten, would be accessible at https://gen-endpoint.com/api/shorten. You can use the "Try it out" section for each endpoint or use tools like curl, Postman, or your browser's address bar (for GET requests) to interact with them.
POST

/api/shorten

Create a new shortened URL. Custom alias (shortCode) and expiration are optional.

Show Static Examples

Example Request Body:

{
  "originalUrl": "https://www.verylongurl.com/path/to/something/interesting?query=param",
  "customAlias": "my-custom-link",
  "description": "Link to an interesting article",
  "expiresAt": "2025-12-31T23:59:59Z",
  "userId": "user_abc_123"
}

Example Response:

{
  "id": "link_nanoid10",
  "shortUrl": "http://localhost:3000/s/my-custom-link",
  "originalUrl": "https://www.verylongurl.com/path/to/something/interesting?query=param",
  "shortCode": "my-custom-link",
  "createdAt": "2024-08-20T10:00:00.000Z",
  "expiresAt": "2025-12-31T23:59:59Z",
  "description": "Link to an interesting article",
  "clickCount": 0
}
Try it out
GET

/api/stats/{shortCode}

Get statistics for a shortened URL. Replace {shortCode} with an actual short code.

Show Static Examples

Example Request Parameters:

Path parameter example: /api/stats/my-custom-link

Example Response:

{
  "shortCode": "my-custom-link",
  "originalUrl": "https://www.verylongurl.com/path/to/something/interesting?query=param",
  "totalClicks": 150,
  "uniqueClicks": 150,
  "clicksByDate": [],
  "topReferrers": [],
  "countries": [],
  "createdAt": "2024-08-20T10:00:00.000Z",
  "description": "Link to an interesting article",
  "expiresAt": "2025-12-31T23:59:59Z"
}
Try it out

Replace placeholders (e.g., {userId}) with actual values in the path above. You can also add/edit query parameters (e.g., ?key=value).

GET

/api/links

List all shortened URLs. Supports optional `userId` query parameter for filtering.

Show Static Examples

Example Request Parameters:

Optional query: /api/links?userId=user_abc_123

Example Response:

{
  "links": [
    {
      "id": "link_nanoid10",
      "shortCode": "my-custom-link",
      "originalUrl": "https://www.verylongurl.com/path/to/something/interesting?query=param",
      "totalClicks": 150,
      "status": "active",
      "createdAt": "2024-08-20T10:00:00.000Z",
      "description": "Link to an interesting article",
      "expiresAt": "2025-12-31T23:59:59Z",
      "userId": "user_abc_123"
    },
    {
      "id": "link_anotherid",
      "shortCode": "another",
      "originalUrl": "https://www.anotherurl.com",
      "totalClicks": 75,
      "status": "expired",
      "createdAt": "2023-01-15T10:00:00.000Z",
      "description": "Old link",
      "expiresAt": "2023-12-31T23:59:59Z",
      "userId": "user_def_456"
    }
  ]
}
Try it out

You can add or change query parameters in the path above (e.g., ?name=User).

GET

/api/links/{linkId}

Get details for a specific short link by its internal ID. Replace {linkId} with an actual link ID.

Show Static Examples

Example Request Parameters:

Path parameter example: /api/links/link_nanoid10

Example Response:

{
  "id": "link_nanoid10",
  "shortCode": "my-custom-link",
  "originalUrl": "https://www.verylongurl.com/path/to/something/interesting?query=param",
  "totalClicks": 150,
  "status": "active",
  "createdAt": "2024-08-20T10:00:00.000Z",
  "description": "Link to an interesting article",
  "expiresAt": "2025-12-31T23:59:59Z",
  "userId": "user_abc_123"
}
Try it out

Replace placeholders (e.g., {userId}) with actual values in the path above. You can also add/edit query parameters (e.g., ?key=value).

DELETE

/api/links/{linkId}

Delete a specific short link by its internal ID. Replace {linkId} with an actual link ID.

Show Static Examples

Example Request Body:

Path parameter example: /api/links/link_nanoid10

Example Response:

{
  "message": "Link link_nanoid10 deleted successfully",
  "deletedAt": "2024-08-20T12:30:00.000Z"
}
Try it out

Replace placeholders (e.g., {userId}) with actual values in the path above.

GET

/s/{shortCode}

Redirector endpoint. Accessing this path with a valid shortCode redirects to the original URL and increments the click count. This is not a JSON API but the core functionality.

Show Static Examples

Example Request Parameters:

Browser access example: http://yourdomain.com/s/my-custom-link

Example Response:

(HTTP 302 Redirect to originalUrl)
Try it out

Replace placeholders (e.g., {userId}) with actual values in the path above. You can also add/edit query parameters (e.g., ?key=value).