HTTP Proxy

SBCanvas.http() makes external HTTP requests proxied through the StreamBot backend. This bypasses CORS restrictions and keeps API keys server-side.

Making Requests

const res = await SBCanvas.http('https://api.example.com/data');
console.log(res.ok);          // true if 2xx
console.log(res.status_code); // 200
console.log(res.body);        // parsed response body

const post = await SBCanvas.http('https://api.example.com/webhook', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: { event: 'goal_reached', amount: 500 }
});

API

SBCanvas.http(url, options?)
Options:
OptionTypeDefaultDescription
methodstring'GET'HTTP method
headersobject{}Request headers
bodyanyundefinedRequest body (auto-serialized)

Response Shape

{
  ok: boolean,        // true if status 2xx
  status_code: number,
  body: any           // parsed JSON or raw text
}

Error Handling

try {
  const res = await SBCanvas.http('https://api.example.com/data');
  if (!res.ok) {
    console.error(`HTTP ${res.status_code}:`, res.body);
    return;
  }
  // use res.body
} catch (err) {
  // network error, timeout, or proxy rejection
  console.error('Request failed:', err);
}

Example: Display Weather

SBCanvas.ready(async () => {
  const res = await SBCanvas.http('https://api.openweathermap.org/data/2.5/weather?q=Austin&appid=YOUR_KEY');
  if (res.ok) {
    const temp = Math.round(res.body.main.temp - 273.15);
    document.getElementById('weather').textContent = `${temp}°C`;
  }
});

Example: Send Discord Webhook on Raid

SBCanvas.activities.on('raid', async (activity) => {
  await SBCanvas.http('https://discord.com/api/webhooks/YOUR_WEBHOOK', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: {
      content: `Raided by ${activity.username} with ${activity.viewers} viewers!`
    }
  });
});

Limits

Requests time out after 30 seconds. The proxy is intended for lightweight API calls, not bulk data transfers.