SDKs and Client Patterns

Livepin currently ships primarily as a REST-first API surface. This page provides practical patterns for building your own lightweight SDK wrappers in JavaScript or Python.

REST client pattern

JavaScript and Python examples

const baseUrl = process.env.LIVEPIN_API_BASE_URL

export async function livepin(path, { method = 'GET', token, body, query } = {}) {
  const qs = query ? `?${new URLSearchParams(query).toString()}` : ''
  const res = await fetch(`${baseUrl}${path}${qs}`, {
    method,
    headers: {
      Authorization: `Bearer ${token}`,
      'Content-Type': 'application/json',
    },
    body: body ? JSON.stringify(body) : undefined,
  })

  if (!res.ok) {
    const errorBody = await res.text()
    throw new Error(`Livepin ${res.status}: ${errorBody}`)
  }

  return res.json()
}

Websocket pattern

Use GET /api/user/generate-websocket-token to mint a token for realtime consumers.

Websocket bootstrap flow

const auth = await livepin('/api/user/generate-websocket-token', { token })
const wsToken = auth.token

const ws = new WebSocket(`wss://your-livepin-stream-endpoint?token=${wsToken}`)
ws.onmessage = (event) => {
  const payload = JSON.parse(event.data)
  console.log('live event', payload)
}

Was this page helpful?