agiledevelopment / url-shortener
A robust PHP SDK for shortening URLs via the 00x.dk API
v1.0.3
2025-11-02 13:33 UTC
Requires
- php: >=7.4
This package is not auto-updated.
Last update: 2026-01-25 14:50:08 UTC
README
A lightweight and robust PHP SDK for shortening URLs using the
00x.dk API.
๐ Features
- โ PHP 7.4+ compatible
- โ PSR-4 autoloading
- โ Input validation and robust error handling
- โ Automatic retry logic on temporary API errors
- โ Easy integration via Composer
- โ Extensible for future endpoints (analytics, deletion, etc.)
๐ฆ Installation
If you're using this SDK in a private project, add the Bitbucket repository to
your composer.json file:
{
"repositories": [
{
"type": "vcs",
"url": "git@bitbucket.org:csriraj/url-shortener-sdk.git"
}
],
"require": {
"agiledevelopment/url-shortener": "^1.0"
}
}
Then run the following command:
composer install
๐งช Usage Example
use AgileDevelopment\Shortener;
try {
// Basic usage
$result = Shortener::create('your_api_token', 'https://www.example.com');
// Optional: specify a custom API base URL or origin domain
// $result = Shortener::create(
// 'your_api_token',
// 'https://www.example.com',
// 'https://staging.00x.dk/api/v1',
// 'https://yourdomain.com'
// );
echo "Shortened URL: " . $result['shortened_url'];
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
โ๏ธ Method Reference
Shortener::create(string $token, string $url, ?string $baseUrl = null, ?string $origin = null): array
| Parameter | Type | Required | Description |
|---|---|---|---|
| $token | string | โ Yes | Your Bearer token from 00x.dk. |
| $url | string | โ Yes | The original URL you want to shorten. |
| $baseUrl | ?string | โ No | Optional custom API base URL. Defaults to https://00x.dk/api/v1. |
| $origin | ?string | โ No | Optional origin domain used for the Origin and Referer headers. |
Returns:
[
'shortened_url' => 'https://00x.dk/abcd1234'
]
Throws:
InvalidArgumentExceptionif the input is invalidRuntimeExceptionif the API request fails after retries
๐ API Requirements
Endpoint:
POST https://00x.dk/api/v1/urls
Headers:
Authorization: Bearer <your_token>
Content-Type: application/json
Accept: application/json
Body:
{
"url": "https://bitbucket.org/csriraj/url-shortener-sdk"
}
Successful Response:
{
"shortened_url": "https://00x.dk/00xdk",
"original_url": "https://bitbucket.org/csriraj/url-shortener-sdk",
"code": "00xdk",
"message": "URL shortened successfully!"
}
๐ License
This project is licensed under the MIT License.
Made with โค๏ธ by **Agile Development**