- Docs
- Getting Started
- SDKs
SDKs
QPub’s official client library is @qpub/sdk for JavaScript and TypeScript (browsers, Node.js, Bun, and React). Use the API and Language controls to switch Socket vs REST and JavaScript vs React.
Install
npm install @qpub/sdk
# or
bun add @qpub/sdk
| Import | Use |
|---|---|
@qpub/sdk | QPub.Socket, QPub.Rest, types |
@qpub/sdk/react | React providers and hooks |
| CDN UMD | Global QPub in the browser |
Import providers and hooks from @qpub/sdk/react (same package).
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.
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.
Call REST from a server action or trusted backend. For browser realtime, switch to Socket and use @qpub/sdk/react.
Next steps
Other languages
Use the REST API and Socket Protocol directly. Official SDKs for other languages are not documented yet.