SDKs overview
Api2Convert offers a suite of Software Development Kits (SDKs) designed to streamline the integration of its file conversion API into various applications. These SDKs abstract the underlying HTTP requests and responses, allowing developers to interact with the API using native language constructs rather than managing raw API calls. The primary goal of providing SDKs is to accelerate development cycles and reduce the boilerplate code required for common tasks such as authentication, request formatting, and response parsing. Api2Convert supports a range of programming languages, ensuring broad compatibility for different development environments and projects.
The SDKs are built to facilitate common use cases, including converting documents (e.g., PDF to DOCX), images (e.g., JPG to PNG), and archives (e.g., ZIP to TAR), as well as leveraging optical character recognition (OCR) functionalities. By using an SDK, developers can focus on their application's core logic, offloading the complexities of API communication to the pre-built libraries. Api2Convert's official documentation provides comprehensive guides and examples for each supported language, detailing how to set up the SDKs, perform conversions, and handle various API responses. The availability of a free tier further enables developers to test and evaluate the SDKs without an initial investment.
Official SDKs by language
Api2Convert provides official SDKs for several popular programming languages, each maintained to ensure compatibility with the latest API versions and features. These SDKs are designed to provide a consistent and idiomatic interface for interacting with the Api2Convert service. The table below outlines the officially supported languages, their corresponding package names, typical installation commands, and their general maturity status as indicated by Api2Convert's development practices.
| Language | Package/Library Name | Install Command | Maturity |
|---|---|---|---|
| PHP | api2convert/php-sdk |
composer require api2convert/php-sdk |
Stable |
| Node.js | @api2convert/node-sdk |
npm install @api2convert/node-sdk |
Stable |
| Python | api2convert-python-sdk |
pip install api2convert-python-sdk |
Stable |
| .NET | Api2Convert.NET.SDK |
dotnet add package Api2Convert.NET.SDK |
Stable |
| Go | github.com/api2convert/go-sdk |
go get github.com/api2convert/go-sdk |
Stable |
| Ruby | api2convert-ruby |
gem install api2convert-ruby |
Stable |
| Java | com.api2convert:java-sdk |
(Maven/Gradle dependency) | Stable |
For detailed usage and specific versioning information, developers should consult the Api2Convert API documentation, which includes specific links to each SDK's repository or package manager page. The documentation also typically provides information on supported API versions and any breaking changes between SDK releases, ensuring developers can maintain compatibility with their projects. The choice of SDK often depends on the existing technology stack of a project or the preferred language of the development team.
Installation
Installing an Api2Convert SDK typically follows the standard package management practices for each respective programming language. Each SDK is distributed through its language's primary package manager, simplifying the process of adding the library to a project and managing dependencies. Before installation, developers need to ensure they have the correct language runtime and package manager installed on their system. For example, Node.js projects require npm or yarn, Python projects use pip, and PHP projects utilize Composer.
PHP
To install the PHP SDK, navigate to your project's root directory in the terminal and execute the following Composer command:
composer require api2convert/php-sdk
Composer will download the SDK and its dependencies, and automatically generate an autoloader file. After installation, you can include the autoloader in your PHP script to start using the SDK.
Node.js
For Node.js applications, the SDK is available via npm. Run the following command in your project directory:
npm install @api2convert/node-sdk
Alternatively, if you are using Yarn:
yarn add @api2convert/node-sdk
Once installed, you can import the module into your JavaScript or TypeScript files.
Python
The Python SDK can be installed using pip, Python's package installer. Open your terminal and run:
pip install api2convert-python-sdk
It is often recommended to install Python packages within a virtual environment to manage project-specific dependencies without conflicts.
.NET
For .NET projects, the SDK is distributed as a NuGet package. You can install it using the .NET CLI:
dotnet add package Api2Convert.NET.SDK
Or through the NuGet Package Manager in Visual Studio.
Go
The Go SDK can be fetched using the go get command:
go get github.com/api2convert/go-sdk
After fetching, you can import the package into your Go source files.
Ruby
For Ruby projects, the SDK is available as a RubyGems gem. Install it via the command line:
gem install api2convert-ruby
Then, require the gem in your Ruby scripts.
Java
For Java projects, the SDK is typically managed through build tools like Maven or Gradle. Add the appropriate dependency to your pom.xml (Maven) or build.gradle (Gradle) file. Consult the Api2Convert Java SDK documentation for the exact dependency coordinates.
Quickstart example
This quickstart example demonstrates how to use the Api2Convert Node.js SDK to convert a file. The general steps involve initializing the client with your API key, specifying the input file, defining the desired output format, and executing the conversion request. This example assumes you have already installed the Node.js SDK and have an Api2Convert API key available.
First, obtain your API key from your Api2Convert account dashboard. You will need this key to authenticate your requests. Best practices suggest storing API keys securely, for example, using environment variables, rather than hardcoding them directly into your application code. For more information on secure API key management, refer to general API key best practices documentation.
Node.js conversion example
This Node.js code snippet shows how to convert a PDF file to a DOCX file using the Api2Convert SDK. It uploads a local PDF file, sets the target format, and then downloads the converted DOCX file.
const Api2Convert = require('@api2convert/node-sdk');
const fs = require('fs');
// Initialize the Api2Convert client with your API key
const client = new Api2Convert({ apiKey: process.env.API2CONVERT_API_KEY });
async function convertPdfToDocx() {
try {
// Path to your input PDF file
const inputFilePath = './input.pdf';
// Path for the output DOCX file
const outputFilePath = './output.docx';
console.log(`Starting conversion of ${inputFilePath} to DOCX...`);
// Perform the conversion
const conversionResult = await client.convert({
file: fs.createReadStream(inputFilePath),
targetFormat: 'docx',
});
// Check if the conversion was successful and download the result
if (conversionResult.success) {
console.log('Conversion successful. Downloading file...');
const outputBuffer = await conversionResult.getFileBuffer();
fs.writeFileSync(outputFilePath, outputBuffer);
console.log(`Converted file saved to ${outputFilePath}`);
} else {
console.error('Conversion failed:', conversionResult.error);
}
} catch (error) {
console.error('An error occurred during conversion:', error);
}
}
convertPdfToDocx();
Before running this code, ensure you have a file named input.pdf in the same directory as your script, and set the API2CONVERT_API_KEY environment variable. This example demonstrates a basic file conversion; the Api2Convert API and SDKs support various other options, such as specifying conversion quality, handling multiple files, and integrating with cloud storage solutions. Refer to the Api2Convert Node.js SDK documentation for advanced configuration and additional conversion types.
Community libraries
While Api2Convert maintains official SDKs for widely used programming languages, the developer community may also contribute unofficial libraries or wrappers. These community-driven projects can sometimes offer support for niche languages, alternative programming paradigms, or specialized integrations not covered by the official offerings. Community libraries often emerge from developers seeking to adapt the API to specific project requirements or to provide a more tailored development experience within a particular ecosystem.
The existence of community libraries can be beneficial, as they demonstrate developer engagement and extend the reach of the Api2Convert platform. However, it is important to note that these libraries are typically not officially supported or maintained by Api2Convert. Developers opting to use community libraries should exercise due diligence, including reviewing the library's source code, checking for active maintenance, and verifying its compatibility with the latest Api2Convert API versions. Resources like GitHub, Stack Overflow, and developer forums are common places to discover and evaluate community-contributed tools. For the most reliable and up-to-date integration, Api2Convert generally recommends using its official SDKs and documentation.