API Documentation

Connect your applications with Flow-Gate's multi-protocol messaging gateway

High-Performance Gateway

Flow-Gate core is written in Go to ensure maximum throughput and microsecond-level latency. It uses NATS JetStream as the underlying message bus, providing guaranteed delivery and exactly-once processing.

Quick Start

1. Get API Key

Generate a static API key from your dashboard

2. Exchange for JWT

Exchange your API key for a short-lived JWT token

POST /token/
3. Connect & Publish

Use the JWT token to connect and publish/subscribe to topics or queues

userid_app_topic

Supported Protocols

HTTP / SSE

RESTful API for simple publishing and real-time streaming.

Publish/Subscribe
WebSocket

Bi-directional channel for complex real-time apps.

Low latency JSON
MQTT

Standard protocol for IoT and constrained devices.

v3.1.1 compliant
Queue (SQS)

Persistent SQS-like messaging with visibility timeouts.

DLQ & Batching

Topic Structure

Topic Format

Topics in Flow-Gate follow a specific structure to organize messages and enforce permissions:

userid_app_topic

userid: Your unique user ID

app: Application identifier

topic: Specific topic within the application

Note: When connecting via MQTT or checking permissions, you use the full string. However, our JWT service handles the prefixing for you automatically based on your token request.

Quick Snippets

HTTP Publish
# Publish a message via HTTP
curl -X POST "https://dev.gateway.flow-gate.kingofshiba.xyz/api/v1/publish" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "topic": "notifications",
    "message": "Hello World!"
  }'
WS Connection
// Connect to Flow-Gate WebSocket
const ws = new WebSocket('wss://api.flow-gate.com/ws?token=YOUR_JWT_TOKEN');

// Handle connection
ws.onopen = () => {
  console.log('Connected to Flow-Gate');
  
  // Subscribe to a topic (Short Name)
  ws.send(JSON.stringify({
    action: "subscribe",
    topic: "notifications"
  }));
};

// Handle incoming messages
ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  // data: { action: "message", topic: "notifications", data: "..." }
  console.log('Received:', data);
};

// Publish a message
function publishMessage(topic, message) {
  ws.send(JSON.stringify({
    action: "publish",
    topic: topic,
    message: message // Can be string or JSON
  }));
} // Note: Server returns no ack for WS publish by default
MQTT Pub/Sub
# Connect via MQTT using mosquitto
mosquitto_pub -h api.flow-gate.com -p 1883 \
  -u "Bearer" \
  -P "YOUR_JWT_TOKEN" \
  -t "notifications" \
  -m "Hello from MQTT!"

# Subscribe to a topic
mosquitto_sub -h api.flow-gate.com -p 1883 \
  -u "Bearer" \
  -P "YOUR_JWT_TOKEN" \
  -t "notifications"
Queue Send
# Send a message to a queue
curl -X POST "https://dev.gateway.flow-gate.kingofshiba.xyz/api/v1/queues/myqueue/messages" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "body": "Your message content"
  }'

Error Codes

400
Bad Request
Invalid parameters or malformed request body
401
Unauthorized
Missing or invalid JWT token
402
Payment Required
Limit reached or insufficient balance (Billing Guard)
403
Forbidden
Insufficient permissions for the requested topic/queue
429
Too Many Requests
Rate limit exceeded
500
Internal Server Error
Server error occurred