zelapi
v0.0.3
Published
Universal JavaScript & TypeScript client for ZelApi — simple, secure, and flexible HTTP requests with support for JSON, text, and media responses.
Downloads
251
Maintainers
Readme
ZelApi is a powerful and versatile JavaScript/TypeScript library that simplifies HTTP requests to the ZelApi service. It's designed to be easy to use, with support for universal parameters, different response types, and a secure way to handle your API key.
Features
- Universal Parameters: Pass parameters as an object or a single string.
- Multiple Response Types: Handle JSON, text, and buffer (for images, videos, etc.) responses with ease.
- Secure API Key Handling: Your API key is sent securely in the request headers.
- TypeScript Support: Written in TypeScript for a better developer experience.
- Easy to Use: A simple and intuitive API that gets the job done.
Installation
You can install zelapi using npm or yarn:
# Using npm
npm install zelapi
# Using yarn
yarn add zelapiHow to Use
ZelApi now offers two clients: ZelApiv1 and ZelApiv2.
ZelApiv1: Connects tozelapioffciall.koyeb.app. It's free to use and does not require an API key.ZelApiv2: Connects tozelapioffciall.dpdns.org. It requires an API key for authenticated access.
ZelApiv1 Usage (No API Key)
Here's a simple example using ZelApiv1:
import { ZelApiv1 } from "zelapi";
// Initialize the v1 client (no API key needed)
const zel = new ZelApiv1();
async function getCat() {
try {
const res = await zel.json("/random/cat");
console.log(res);
} catch (error) {
console.error("Error fetching cat:", error);
}
}
getCat();ZelApiv2 Usage (API Key Required)
To use ZelApiv2, you must provide an API key.
import { ZelApiv2 } from "zelapi";
// Initialize the v2 client with your API key
const zel = new ZelApiv2({
apiKey: "YOUR_API_KEY",
});
async function getDog() {
try {
const res = await zel.json("/random/dog");
console.log(res);
} catch (error) {
console.error("Error fetching dog:", error);
}
}
getDog();Universal Parameters
You can pass parameters as an object or a single string.
Object Parameters
import { ZelApi } from "zelapi";
const zel = new ZelApi();
async function search() {
try {
const res = await zel.json("/search", {
q: "nature",
type: "image",
});
console.log(res);
} catch (error) {
console.error("Error searching:", error);
}
}
search();String Parameter
If you pass a string as the second argument, it will be treated as the text parameter.
import { ZelApi } from "zelapi";
const zel = new ZelApi();
async function convert() {
try {
const res = await zel.json("/convert/to-emoji", "Hello World");
console.log(res);
} catch (error) {
console.error("Error converting:", error);
}
}
convert();Handling Different Response Types
ZelApi can handle different response types, such as JSON, text, and buffers.
JSON Response
The json() method returns a JSON object.
const res = await zel.json("/random/cat");
console.log(res);Text Response
The text() method returns a string.
const res = await zel.text("/random/quote");
console.log(res);Buffer Response
The buffer() method returns a Buffer, which is useful for handling images, videos, and other binary files.
import { ZelApi } from "zelapi";
import fs from "fs";
const zel = new ZelApi();
async function getCatImage() {
try {
const buffer = await zel.buffer("/random/cat-image");
fs.writeFileSync("cat.jpg", buffer);
console.log("Cat image saved!");
} catch (error) {
console.error("Error fetching cat image:", error);
}
}
getCatImage();Contributing
Contributions are welcome! Please read our Contributing Guidelines and Code of Conduct before submitting a pull request.
Security
If you discover a security vulnerability, please report it to us by following the instructions in our Security Policy.
License
This project is licensed under the MIT License.

