Skip to main content
HydroGo
Frontends@hydrohq/client

@hydrohq/client

A typed, dependency-free fetch client for the public API. Works in browsers, Node 20+, Deno, Bun and edge runtimes.

@hydrohq/client wraps the public endpoints with TypeScript types, request timeouts, size-capped responses and a proper error class. You can also call the API with plain fetch; the client just removes boilerplate.

Use from GitHub

Use @hydrohq/client directly from GitHub (packages/client in hydrohq/hydrogo), or generate a standalone typed SDK directly from your HydroGo instance:

BASH
git clone --depth 1 https://github.com/hydrohq/hydrogo.git
# Use ./hydrogo/packages/client directly, or generate a standalone typed SDK:
hydro sdk generate --content-types-dir content-types --out ./sdk --lang typescript

Create a client

TS
import { createHydroGoClient } from '@hydrohq/client';

const hydro = createHydroGoClient({
  origin: 'https://cms.example.com',
  timeoutMs: 8000,        // default 15000, maximum 120000
  // fetch: customFetch,  // inject your own fetch (tests, edge runtimes)
});
OptionDefaultMeaning
originrequiredBase URL of your HydroGo, without a trailing path.
timeoutMs15000Per-request timeout. Capped at 120000.
fetchglobal fetchCustom fetch implementation.
signalnoneAn AbortSignal applied to every request.

Methods

MethodCallsReturns
getPage(locale, slug)GET /api/v1/pages/by-slugPage
listPages(locale, limit = 20)GET /api/v1/pagesPageSummary[]
listNews(locale, limit = 20)GET /api/v1/newsNewsItem[]
getNews(locale, slug)GET /api/v1/news/by-slugNewsItem
listContent<T>(type, query)GET /api/v1/content/{type}{ data: T[], metadata }
getContent<T>(type, id, locale?)GET /api/v1/content/{type}/{id}T
memberLogin, memberRegister, memberRefresh, memberLogout, memberDevices, memberMe/api/v1/mobile/member/*Token pairs, devices, profile

Every method takes an optional last argument { signal } for cancellation. The query for listContent accepts limit, offset, sort, search, locale and filter.

Examples

TS
const page = await hydro.getPage('en', 'about');
const latest = await hydro.listNews('en', 5);

type Faq = { id: string; question: string; answer: string };
const faq = await hydro.listContent<Faq>('faq', { limit: 20, search: 'refund' });
const one = await hydro.getContent<Faq>('faq', faq.data[0].id);

Error handling

Failures throw HydroGoError with status, code, message and requestId. Quote the request id when you report a problem.

TS
import { HydroGoError } from '@hydrohq/client';

try {
  await hydro.getPage('en', 'missing');
} catch (err) {
  if (err instanceof HydroGoError && err.status === 404) {
    // render your 404
  } else if (err instanceof HydroGoError) {
    console.error(err.code, err.message, err.requestId);
  } else {
    throw err;
  }
}
  • Requests time out after 15 seconds by default.
  • Response bodies are size-capped to protect your server from runaway responses.
  • Member methods never send browser cookies (credentials: 'omit').

Generating a full SDK

The client is hand-written for the public surface. For admin tooling and every OpenAPI type, generate an SDK:

BASH
hydro sdk generate --lang typescript --out ./sdk
hydro sdk generate --openapi docs/api/public-content-v1.openapi.json --lang all --out ./sdk

Without the client

Plain fetch works everywhere. Unwrap data yourself:

TS
const res = await fetch('https://cms.example.com/api/v1/news?locale=en&limit=5');
if (!res.ok) throw new Error((await res.json()).request_id);
const { data } = await res.json();