API Reference
Complete reference for all glyde methods and configuration options.
plane(config?)
Creates a new HTTP client instance. Every call returns an independent instance with its own config and interceptors. Available as both default and named export.
import plane from "glyde"
// or
import { plane } from "glyde"Request Config
interface RequestConfig {
url?: string
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS"
baseURL?: string
headers?: Record<string, string>
params?: Record<string, string | number | boolean>
data?: unknown
timeout?: number
signal?: AbortSignal
responseType?: "json" | "text" | "blob" | "arrayBuffer" | "stream"
withCredentials?: boolean
}| Field | Default | Description |
|---|---|---|
baseURL | "" | Prepended to relative URLs |
timeout | 0 | Milliseconds before abort (0 = no timeout) |
responseType | "json" | How to parse the response body |
withCredentials | false | If true, sets credentials: "include" |
headers | JSON defaults | Content-Type and Accept set to application/json |
HTTP Methods
const api = plane({ baseURL: "https://api.example.com" })
// GET — no body sent, even if data provided
api.get<User[]>("/users")
api.get("/search", { params: { q: "glyde", page: 1 } })
// POST, PUT, PATCH — second arg is request body
api.post<User>("/users", { name: "Yash" })
api.put("/users/1", updatedUser)
api.patch("/users/1", { name: "New Name" })
// DELETE, HEAD — no body
api.delete("/users/1")
api.head("/health")
// Generic request
api.request({ method: "GET", url: "/custom" })
// File upload — auto-removes Content-Type for correct boundary
api.upload("/files", formData)
// Streaming — returns ReadableStream without consuming body
api.stream("/events")Timeout
Set a timeout in milliseconds. When exceeded, a TimeoutError is thrown. Internally uses AbortController.
// Instance-level timeout
const api = plane({ timeout: 5000 })
// Per-request override
await api.get("/slow", { timeout: 15000 })Cancellation
Pass an AbortSignal to cancel requests manually.
const controller = new AbortController()
// Pass signal to request
api.get("/data", { signal: controller.signal })
// Cancel it
controller.abort()Credentials
// Default: credentials: "same-origin"
const api = plane()
// Send cookies cross-origin: credentials: "include"
const api = plane({ withCredentials: true })File Upload
When body is FormData or URLSearchParams, Content-Type is automatically removed so the browser sets the correct multipart boundary.
const form = new FormData()
form.append("file", file)
form.append("name", "avatar")
// Content-Type is automatically removed — browser sets it with boundary
await api.upload("/upload", form)
// URLSearchParams also auto-removes Content-Type
const params = new URLSearchParams({ grant_type: "password" })
await api.post("/token", params)Streaming
Returns a ReadableStream without consuming the response body.
const { data: stream } = await api.stream("/events")
// data is a ReadableStream — body is NOT consumed
const reader = stream.getReader()
while (true) {
const { done, value } = await reader.read()
if (done) break
console.log(new TextDecoder().decode(value))
}