Unofficial API wrapper for the E-Z.host API
npm install e-zhost-js
# or
yarn add e-zhost-js
# or
pnpm add e-zhost-jsThe EZHostSDK class provides a convenient wrapper around all API methods:
import { EZHostSDK } from 'e-zhost-js';
const client = new EZHostSDK('YOUR_API_KEY');const result = await client.shortenUrl('https://example.com');
console.log('Shortened URL:', result.shortendUrl);
console.log('Deletion URL:', result.deletionUrl);With options:
const result = await client.shortenUrl('https://example.com', {
maxUrlLength: 2048,
timeout: 5000,
});const result = await client.createPaste('console.log("Hello World!")', {
title: 'Example Code',
description: 'A simple hello world example',
language: 'javascript',
});
console.log('Paste URL:', result.pasteUrl);
console.log('Raw URL:', result.rawUrl);import { createReadStream } from 'fs';
const fileStream = createReadStream('./image.jpg');
const result = await client.uploadFile(fileStream, 'image.jpg');
if (result.success) {
console.log('Image URL:', result.imageUrl);
console.log('Raw URL:', result.rawUrl);
console.log('Deletion URL:', result.deletionUrl);
} else {
console.error('Upload failed:', result.message);
}You can also upload from a Buffer:
const buffer = await fs.promises.readFile('./image.png');
const result = await client.uploadFile(buffer, 'image.png');You can delete files, pastes, and shortened URLs using either the full deletion URL or just the deletion key:
const result = await client.deleteFile(uploadResult.deletionUrl);
console.log(result.message);const result = await client.deletePaste(pasteResult.deletionUrl);
console.log(result.message);const result = await client.deleteShortener(shortenerResult.deletionUrl);
console.log(result.message);If you prefer not to use the SDK class, you can use the standalone functions directly:
import {
shortenUrl,
createPaste,
uploadFile,
deleteFile,
deletePaste,
deleteShortener,
} from 'e-zhost-js';
import axios from 'axios';
const api = axios.create({
baseURL: 'https://api.e-z.host',
headers: { key: 'YOUR_API_KEY' },
});
const result = await shortenUrl(api, 'https://example.com');
await deleteShortener(api, result.deletionUrl);All types are exported for TypeScript users:
import type {
ShortenUrlOptions,
UploadFileOptions,
CreatePasteOptions,
DeleteOptions,
ShortenerResponse,
FileUploadResponse,
PasteResponse,
DeleteResponse,
ShortenerDocument,
PasteDocument,
UploaderInfo,
ShortenerRequest,
CreatePasteRequest,
} from 'e-zhost-js';| Method | Description |
|---|---|
shortenUrl(url, options?) |
Shorten a URL |
createPaste(text, options?) |
Create a text paste |
uploadFile(file, filename?, options?) |
Upload a file |
deleteFile(deletionUrlOrKey, options?) |
Delete an uploaded file |
deletePaste(deletionUrlOrKey, options?) |
Delete a paste |
deleteShortener(deletionUrlOrKey, options?) |
Delete a shortened URL |
success: booleanshortendUrl: string - The shortened URLdeletionUrl: string - URL to delete the shortened linkdocument?: ShortenerDocument - Additional metadata
success: booleanpasteUrl: string - URL to view the pasterawUrl?: string - URL to view raw paste contentdeletionUrl: string - URL to delete the pastedocument?: PasteDocument - Additional metadata including uploader info
success: booleanimageUrl?: string - Public URL for viewing the filerawUrl?: string - Direct CDN URLdeletionUrl?: string - URL to delete the file
success: booleanmessage: string - Success or error message
MIT