e-zhost-js
v1.1.1
Published
Unofficial API wrapper for E-Z.host
Readme
e-zhost-js
Unofficial API wrapper for the E-Z.host API
Installation
npm install e-zhost-js
# or
yarn add e-zhost-js
# or
pnpm add e-zhost-jsUsage
Using the SDK Class
The EZHostSDK class provides a convenient wrapper around all API methods:
import { EZHostSDK } from 'e-zhost-js';
const client = new EZHostSDK('YOUR_API_KEY');URL Shortener
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,
});Create Paste
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);File Upload
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');Deleting Resources
You can delete files, pastes, and shortened URLs using either the full deletion URL or just the deletion key:
Delete a File
const result = await client.deleteFile(uploadResult.deletionUrl);
console.log(result.message);Delete a Paste
const result = await client.deletePaste(pasteResult.deletionUrl);
console.log(result.message);Delete a Shortened URL
const result = await client.deleteShortener(shortenerResult.deletionUrl);
console.log(result.message);Standalone Functions
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);Types
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';API Reference
EZHostSDK Methods
| 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 |
Response Types
ShortenerResponse
success: booleanshortendUrl: string - The shortened URLdeletionUrl: string - URL to delete the shortened linkdocument?: ShortenerDocument - Additional metadata
PasteResponse
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
FileUploadResponse
success: booleanimageUrl?: string - Public URL for viewing the filerawUrl?: string - Direct CDN URLdeletionUrl?: string - URL to delete the file
DeleteResponse
success: booleanmessage: string - Success or error message
License
MIT
