- Docs
- Getting Started
- SDKs
SDKs
QPub ships official client libraries for JavaScript/TypeScript, React, and Go. Use the API and Language controls to switch Socket vs REST and the sample language.
Install
npm install @qpub/sdkImport providers and hooks from @qpub/sdk/react (same package).
go get github.com/qpubio/[email protected]
Requires Go 1.22 or newer.
| Import | Use |
|---|---|
@qpub/sdk | QPub.Socket, QPub.Rest, types (JavaScript / TypeScript) |
@qpub/sdk/react | React providers and hooks (same npm package) |
github.com/qpubio/qpub-go | qpub.NewSocket, qpub.NewRest (Go) |
CDN UMD (@qpub/sdk) | Global QPub in the browser |
Quick example
Use the Socket client for realtime subscribe and publish:
import { QPub } from "@qpub/sdk";
const socket = new QPub.Socket({
apiKey: process.env.QPUB_API_KEY,
});
socket.connection.on("connected", async () => {
const ch = socket.channels.get("news");
await ch.subscribe((msg) => console.log(msg.data));
});Do not put a production API key secret in a public browser app. Use token auth instead.
For browsers, pass a JWT or token request into SocketProvider — not a secret API key in a public env var.
Run on a trusted server or backend. Keep the API key in environment variables; use token auth when issuing credentials to other clients.
Use the REST client for server publish, tokens, and queues:
import { QPub } from "@qpub/sdk";
const rest = new QPub.Rest({
apiKey: process.env.QPUB_API_KEY,
});
await rest.channels.get("news").publish({ headline: "Ship it" });Keep the API key on a trusted server. Use queues and token issue from the same client.
QPub's React hooks/providers (@qpub/sdk/react) are Socket-only. REST is recommended for server-side use, so there's no dedicated React integration — but you can still call the plain QPub.Rest client from React (a server action or trusted backend). For browser realtime, switch to Socket and use @qpub/sdk/react.
REST and queues are a natural fit for Go services. See qpub-go examples for queue workers and token flows.
Next steps
Other languages
Use the REST API and Socket Protocol directly when no official SDK exists for your stack.