SDKs overview
Cutt.ly provides an API that allows developers to programmatically shorten URLs, manage custom links, and access link analytics. The API is primarily accessed via simple HTTP GET requests, authenticated using a unique API key. To facilitate integration, Cutt.ly offers official SDKs for popular programming languages, alongside a selection of community-maintained libraries, which encapsulate the API's functionality into language-specific methods and objects. These SDKs and libraries abstract the underlying HTTP requests, simplifying the development process for tasks like creating short URLs or retrieving link statistics.
Developers can utilize these tools to embed URL shortening capabilities directly into their applications, automate link generation for marketing campaigns, or integrate custom link management into content management systems. The Cutt.ly API documentation provides comprehensive details on available endpoints, parameters, and response formats, serving as the primary reference for all integrations, whether using an SDK or making direct API calls.
Official SDKs by language
Cutt.ly maintains official SDKs to support direct integration with its API. These SDKs are designed to provide a structured way to interact with the Cutt.ly service using familiar programming constructs. The following table outlines the officially supported SDKs, their respective package names, and typical installation commands.
| Language | Package Name | Installation Command | Maturity |
|---|---|---|---|
| Python | cuttpy |
pip install cuttpy |
Stable |
| PHP | cuttly/cuttly-php |
composer require cuttly/cuttly-php |
Stable |
These official SDKs are typically maintained by Cutt.ly to ensure compatibility with the latest API versions and to provide a consistent developer experience as detailed in the Cutt.ly API documentation.
Installation
Installation of Cutt.ly SDKs follows standard package management practices for each respective language environment. Below are the steps for installing the official Python and PHP SDKs.
Python SDK Installation
To install the official Python SDK, cuttpy, use pip, the Python package installer. Ensure you have Python and pip installed on your system.
pip install cuttpy
After installation, you can import the library into your Python projects.
PHP SDK Installation
For the official PHP SDK, cuttly/cuttly-php, Composer is used for dependency management. Ensure you have Composer installed globally.
composer require cuttly/cuttly-php
Once Composer has finished, the SDK will be available in your project's vendor/ directory, and you can include Composer's autoloader in your PHP scripts.
Quickstart example
This section provides a quickstart example demonstrating how to shorten a URL using the Cutt.ly Python SDK. Before running the example, ensure you have installed the cuttpy package and have your Cutt.ly API key ready. You can obtain an API key from your Cutt.ly account settings.
Python Quickstart
First, import the Cuttly client and initialize it with your API key. Then, call the shorten method with the long URL you wish to shorten.
from cuttpy import Cuttly
# Replace with your actual Cutt.ly API key
API_KEY = "YOUR_CUTTLY_API_KEY"
# Initialize the Cuttly client
cuttly_client = Cuttly(API_KEY)
# The long URL to shorten
long_url = "https://www.example.com/this-is-a-very-long-url-that-needs-to-be-shortened-for-sharing"
try:
# Shorten the URL
shortened_url_data = cuttly_client.shorten(long_url)
# Check if the shortening was successful
if shortened_url_data and shortened_url_data['status'] == 7:
print(f"Original URL: {long_url}")
print(f"Shortened URL: {shortened_url_data['shortLink']}")
print(f"Full data: {shortened_url_data}")
else:
error_message = shortened_url_data.get('fullLink', 'Unknown error')
print(f"Error shortening URL: {error_message} (Status: {shortened_url_data.get('status')})")
except Exception as e:
print(f"An error occurred: {e}")
The status code 7 typically indicates a successful URL shortening operation according to the Cutt.ly API documentation. Other status codes denote various error conditions, such as an invalid API key or an invalid URL format.
Community libraries
In addition to the official SDKs, the developer community has contributed libraries for Cutt.ly in other programming languages. These libraries are developed and maintained independently, often reflecting specific community needs or preferences. While not officially supported by Cutt.ly, they can offer alternative integration paths.
Node.js/JavaScript
For Node.js environments, several community-driven packages exist to interact with the Cutt.ly API. One common approach involves using a generic HTTP client like axios or node-fetch to make direct API calls, abstracting the Cutt.ly API key and endpoint details within a custom module. An example of a community-contributed library for Node.js can be found on npm, often named similarly to cuttly-js or node-cuttly, although their maintenance status can vary.
Developers using Node.js often prefer making direct HTTP requests due to the API's simplicity, as described in the Fetch API documentation for web environments or using axios for server-side applications.
const axios = require('axios');
const API_KEY = 'YOUR_CUTTLY_API_KEY';
const LONG_URL = 'https://www.example.com/another-long-url-for-shortening-in-javascript';
async function shortenUrl(longUrl) {
try {
const response = await axios.get(`https://cutt.ly/api/api.php?key=${API_KEY}&short=${encodeURIComponent(longUrl)}`);
const data = response.data.url;
if (data && data.status === 7) {
console.log(`Original URL: ${longUrl}`);
console.log(`Shortened URL: ${data.shortLink}`);
} else {
console.error(`Error shortening URL: ${data.fullLink || 'Unknown error'} (Status: ${data.status})`);
}
} catch (error) {
console.error(`An error occurred: ${error.message}`);
}
}
shortenUrl(LONG_URL);
Ruby
The Ruby community also provides gems for interacting with URL shortening services, including Cutt.ly. These gems typically wrap the HTTP request logic, making it more idiomatic for Ruby developers. Searching for "cuttly gem" on platforms like RubyGems.org can yield several options, each with its own documentation and usage examples.
When using community libraries, it is advisable to review their documentation, contribution history, and open issues to assess their reliability and ongoing support. The official Cutt.ly API reference remains the ultimate source of truth for API behavior and capabilities, regardless of the client library used.