Guide · ~10 min

How to add chat to your app

Building real-time chat from scratch — message storage, WebSocket fan-out, presence, history, permissions — is weeks of work. With a chat API you wire it up in an afternoon. Here's the whole flow with Guildyx.

1. Get an API key

Sign up and you'll get a gx_live_… key. It identifies your app and selects your isolated database. Send it as the x-api-key header on every request.

2. Register and log in your users

const API = "https://au.dc.guildyx.com";
const KEY = "gx_live_...";

// register (do this from your server)
await fetch(`${API}/api/auth/register`, {
  method: "POST",
  headers: { "x-api-key": KEY, "content-type": "application/json" },
  body: JSON.stringify({ email, username, password }),
});

// log in -> accessToken (a JWT for this user)
const { accessToken } = await (await fetch(`${API}/api/auth/login`, {
  method: "POST",
  headers: { "x-api-key": KEY, "content-type": "application/json" },
  body: JSON.stringify({ email, password }),
})).json();

3. Send a message

await fetch(`${API}/api/channels/${channelId}/messages`, {
  method: "POST",
  headers: {
    "x-api-key": KEY,
    "Authorization": `Bearer ${accessToken}`,
    "content-type": "application/json",
  },
  body: JSON.stringify({ content: "Hello world" }),
});

4. Receive messages live (WebSocket)

import { io } from "socket.io-client";

const socket = io(API, { auth: { apiKey: KEY, token: accessToken } });
socket.emit("channel:join", channelId);

socket.on("message:new",    (msg) => render(msg));
socket.on("message:edit",   (msg) => update(msg));
socket.on("message:delete", ({ id }) => remove(id));
socket.on("typing:update",  ({ userId }) => showTyping(userId));

That's a working real-time chat: persisted history, live delivery, typing and presence — without running any of that infrastructure yourself. From here you can add servers, roles, DMs, reactions and voice with the same API. See the full API reference.

Ship chat today — from $9.99/mo

Get your API key →

Related