Skip to content

Clients and tools#

SurfaceLens is plain HTTPS and JSON. Every example in these docs uses a standard HTTP client: curl, fetch in TypeScript, or httpx in Python. There is no SDK to install during the preview.

The OpenAPI description#

openapi.yaml describes every operation, parameter, schema, error and webhook in OpenAPI 3.1. The reference pages are generated from it, and every example in it is checked against its schemas, so it is the most precise description of the API there is.

Use it to:

  • generate a typed client, for example with openapi-typescript and openapi-fetch for TypeScript, or openapi-python-client for Python;
  • import the API into Postman, Insomnia or Bruno;
  • mock the API in your tests with Prism or a similar tool, using the examples it contains.
curl -O https://docs.surfacelens.app/openapi.yaml
npx openapi-typescript openapi.yaml -o surfacelens.d.ts

The file's info.version changes with each preview release. Regenerate when the changelog lists a change you need.

curl#

Examples set the key in an environment variable and use -G with -d for query parameters, so long queries stay readable:

export SURFACELENS_KEY=sl_test_9xKq2VwM7pLr4TnB8cYz3HdF

curl -G https://api.surfacelens.app/v1/airports/VTBS/entities \
  -H "Authorization: Bearer $SURFACELENS_KEY" \
  -d type=aircraft \
  -d limit=10

For streams, add -N so curl prints events as they arrive. Pipe JSON responses through jq to read them.

TypeScript#

Examples use the global fetch of Node.js 20 and later, Bun, Deno, Cloudflare Workers and browsers. A small wrapper keeps the key and error handling in one place:

surfacelens.ts
const BASE = "https://api.surfacelens.app/v1";

export async function sl<T>(path: string, init: RequestInit = {}): Promise<T> {
  const res = await fetch(BASE + path, {
    ...init,
    headers: {
      Authorization: `Bearer ${process.env.SURFACELENS_KEY}`,
      "Content-Type": "application/json",
      ...init.headers,
    },
  });
  if (!res.ok) {
    const problem = await res.json();
    throw new Error(`${problem.code}: ${problem.detail} (${problem.request_id})`);
  }
  return res.json() as Promise<T>;
}

Do not put a live key in browser code. Call SurfaceLens from your server, or issue a key per kiosk or display with read scopes for one airport only.

For streams, read res.body as text and split it into events on blank lines, as shown in Subscribe to changes. The browser's EventSource cannot send an Authorization header, so use fetch there too.

Python#

Examples use httpx, which supports both synchronous and async code and streaming responses. Make one client and reuse it:

import os, httpx

client = httpx.Client(
    base_url="https://api.surfacelens.app/v1",
    headers={"Authorization": f"Bearer {os.environ['SURFACELENS_KEY']}"},
    timeout=10,
)

aircraft = client.get("/airports/VTBS/entities", params={"type": "aircraft"})
aircraft.raise_for_status()

For streams, use client.stream("GET", ...) and iter_lines(). Set timeout=httpx.Timeout(10, read=45), so a connection that stops sending keep-alives is noticed.

Other languages#

Anything that can make an HTTPS request with a header works. Two things to get right:

  • Time. Send UTC timestamps with a Z suffix. Most languages default to local time or an offset; convert explicitly.
  • Streams. Use a client that exposes the response body as it arrives, not one that waits for the response to finish.