starlight-api
v1.0.2
Published
Starlight Programming Language API Utilities with GET, POST, headers, and auth
Maintainers
Readme
Starlight API Utilities
Developer: Dominex
Description: Starlight API Utilities provide a low-level and flexible HTTP client for the Starlight Programming Language. It supports HTTP and HTTPS requests with JSON handling, headers, authentication, query parameters, timeouts, and reusable API clients.
This package is designed as a foundation utility for building integrations, bots, services, and automation tools with clean and minimal code.
Installation
npm install starlight-api
Import
import api from "starlight-api"
Or using named imports:
import { request, createClient } from "starlight-api"
Basic GET Request
` const response = await api.request({ url: "https://example.com/data" })
print(response.data) `
POST Request with JSON Body
` const response = await api.request({ method: "POST", url: "https://example.com/api", body: { name: "Starlight", version: "1.0.0" } })
print(response.data) `
JSON bodies are automatically converted and parsed.
Query Parameters
const response = await api.request({ url: "https://example.com/search", params: { q: "starlight", page: 1 } })
Custom Headers
const response = await api.request({ url: "https://example.com/secure", headers: { "X-Token": "abc123" } })
Basic Authentication
const response = await api.request({ url: "https://example.com/private", auth: { username: "user", password: "pass" } })
Timeout Control
const response = await api.request({ url: "https://example.com/slow", timeout: 5000 })
Default timeout is 15000 milliseconds.
Using createClient
The createClient function allows you to create a reusable API client with default settings.
` const client = createClient({ baseURL: "https://api.example.com", headers: { "Authorization": "Bearer TOKEN" } })
const users = await client.get("/users") const post = await client.post("/posts", { title: "Hello" }) `
Client Methods
- client.request(method, path, options) - client.get(path, options) - client.post(path, body, options) - client.put(path, body, options) - client.patch(path, body, options) - client.delete(path, options)
Request Options
- method – HTTP method (default GET) - url – Full request URL - headers – Custom HTTP headers - body – Request body (object, string, or buffer) - params – Query parameters object - auth – Basic authentication - timeout – Timeout in milliseconds
Response Object
Every request returns an object with:
- ok – Boolean success status - status – HTTP status code - statusText – HTTP status message - headers – Response headers - data – Parsed response data - raw – Raw response text
Notes
- Supports HTTP and HTTPS - No external dependencies - JSON handled automatically - Designed for advanced workflows with minimal code - Ideal base for services, bots, and integrations Official Documentation
