api.get()
Executes a GET request through the full WELD pipeline.
Signature
Section titled “Signature”api.get(path, schema?, options?): WeldResponse<T>Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
path |
keyof TRouter |
Yes | Route path — autocompleted from your AppRouter |
schema |
ZodSchema<T> |
No | Zod schema for runtime validation. Omit for zero-config mode |
options |
WeldRequestOptions |
No | Per-request configuration |
Returns
Section titled “Returns”WeldResponse<T> — contains signal, promise, and abort.
Examples
Section titled “Examples”Zero-config
Section titled “Zero-config”const { promise } = api.get('v1/products')const data = await promise // type: unknownWith validation
Section titled “With validation”const { promise } = api.get('v1/products', z.array(ProductSchema))const products = await promise // type: Product[]With query params
Section titled “With query params”const { promise } = api.get('v1/products', z.array(ProductSchema), { query: { page: 1, limit: 20, category: 'electronics' },})With custom headers
Section titled “With custom headers”const { signal } = api.get('v1/products', z.array(ProductSchema), { headers: { 'X-Custom-Header': 'value' },})With cancellation
Section titled “With cancellation”const { promise, abort } = api.get('v1/products', z.array(ProductSchema))
// Cancel after 2 seconds if not resolvedsetTimeout(abort, 2000)
const products = await promiseWith reactive signals
Section titled “With reactive signals”const { signal } = api.get('v1/products', z.array(ProductSchema))
signal.status.subscribe((status) => { console.log('Status changed:', status) // 'loading' → 'success'})
signal.data.subscribe((products) => { console.log('Products:', products)})