Proxy Methods

Fetch external content through the TelemetryOS proxy service to handle CORS restrictions with intelligent caching and bandwidth management.

Proxy Methods

Fetch external content through the TelemetryOS proxy service.

Overview

The Proxy Methods provide access to external content through the TelemetryOS platform, automatically handling CORS restrictions, caching, authentication, and bandwidth management across your device fleet.

About CORS: TelemetryOS applications run in browser contexts where Cross-Origin Resource Sharing (CORS) policies apply. The Proxy API solves CORS limitations by routing requests through the TelemetryOS platform. For complete CORS information, see Understanding CORS.

Importing

import { proxy } from '@telemetryos/sdk';

Methods

fetch()

Fetch content from external URLs through the platform proxy.

Signature:

async fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>

Parameters:

  • input - URL as string, URL object, or Request object
  • init - Optional fetch options (method, headers, body, etc.)

Returns: Promise<Response> - Standard Response object

Example:

const response = await proxy().fetch('https://api.openweathermap.org/data/2.5/weather?q=Seattle&appid=YOUR_API_KEY');
const data = await response.json();

Caching Behavior

The TelemetryOS proxy implements intelligent caching to optimize performance across device fleets.

Default Caching

  • GET requests: 60-second cache by default
  • Other methods: No default caching

Why Caching Matters

When hundreds or thousands of devices request the same external content simultaneously, the proxy cache prevents overwhelming external servers thus preventing you from being rate limited or blocked. Always use caching whenever possible.

Controlling Cache with Headers

Control proxy caching using standard Cache-Control request headers:

// Force fresh fetch (bypass cache)
const response = await proxy().fetch('https://jsonplaceholder.typicode.com/posts', {
  headers: { 'Cache-Control': 'no-cache' }
});

Common directives: no-cache (bypass cache), no-store (never cache), max-age=<seconds> (custom cache duration).

Next Steps


What’s Next