A lightweight TypeScript/JavaScript SDK for Short.io's URL shortening API, designed specifically for browser environments with public key authentication.
- 🌐 Browser-first: Optimized for client-side applications
- 🔑 Public Key Auth: Works with Short.io public API keys
- 📦 Lightweight: Minimal dependencies, small bundle size
- 🎯 TypeScript: Full type safety with TypeScript support
- 🚀 Modern: Uses fetch API and ES modules
npm install @short.io/client-browser
import { createClient } from '@short.io/client-browser';
// Initialize the client with your public API key
const client = createClient({
publicKey: 'your-public-api-key'
});
// Create a short link
const link = await client.createLink({
originalURL: 'https://example.com/very-long-url',
domain: 'your-domain.com'
});
console.log(link.shortURL); // https://your-domain.com/abc123
// Expand a short link
const expanded = await client.expandLink({
domain: 'your-domain.com',
path: 'abc123'
});
console.log(expanded.originalURL); // https://example.com/very-long-url
Creates a new Short.io client instance.
Parameters:
config.publicKey
(string): Your Short.io public API keyconfig.baseUrl
(string, optional): Custom API base URL (defaults tohttps://api.short.io/links
)
Creates a new short link.
Parameters:
request.originalURL
(string): The URL to shortenrequest.domain
(string): Your Short.io domainrequest.path
(string, optional): Custom path for the short linkrequest.title
(string, optional): Title for the linkrequest.tags
(string[], optional): Tags for organizationrequest.allowDuplicates
(boolean, optional): Allow duplicate links
Returns: Promise
Expands a short link to get its details.
Parameters:
request.domain
(string): The Short.io domainrequest.path
(string): The path of the short link
Returns: Promise
const link = await client.createLink({
originalURL: 'https://github.com/Short-io/client-browser',
domain: 'your-domain.com',
title: 'Short.io Browser SDK'
});
const link = await client.createLink({
originalURL: 'https://docs.short.io',
domain: 'your-domain.com',
path: 'docs'
});
const link = await client.createLink({
originalURL: 'https://example.com',
domain: 'your-domain.com',
tags: ['marketing', 'campaign-2024']
});
try {
const link = await client.createLink({
originalURL: 'https://example.com',
domain: 'your-domain.com'
});
} catch (error) {
console.error('Failed to create link:', error.message);
}
This SDK works in all modern browsers that support:
- Fetch API
- ES2018 features
- Promises/async-await
For older browsers, you may need polyfills for the fetch API.
The SDK is available in multiple formats:
- ES Modules:
dist/index.esm.js
(recommended for modern bundlers) - CommonJS:
dist/index.js
(Node.js compatibility) - UMD:
dist/index.umd.js
(direct browser usage)
<script src="https://unpkg.com/@short.io/client-browser/dist/index.umd.js"></script>
<script>
const client = ShortioClient.createClient({
publicKey: 'your-public-api-key'
});
</script>
- Visit your Short.io dashboard
- Go to Integrations & API
- Create a new public API key for your domain
The SDK includes full TypeScript definitions. All methods and responses are fully typed:
import type { CreateLinkRequest, CreateLinkResponse } from '@short.io/client-browser';
const request: CreateLinkRequest = {
originalURL: 'https://example.com',
domain: 'your-domain.com'
};
const response: CreateLinkResponse = await client.createLink(request);
Contributions are welcome! Please feel free to submit a Pull Request.
MIT © Short.io