Platform
SDK and client patterns
Implementation patterns for integrating Tether APIs from multiple languages.
Use a shared HTTP client abstraction that handles auth and retries consistently.
Baseline HTTP requirements
- Base URL per environment.
- Bearer token injection on authenticated calls.
- Structured parsing for non-2xx responses.
- Timeouts and idempotent retry policy.
JavaScript example
Retries are limited to idempotent methods, so a failed POST is never sent
twice:
const IDEMPOTENT_METHODS = new Set(['GET', 'HEAD', 'PUT', 'DELETE']);
const TIMEOUT_MS = 10000;
export async function request(path, options = {}) {
const method = (options.method ?? 'GET').toUpperCase();
const maxAttempts = IDEMPOTENT_METHODS.has(method) ? 3 : 1;
for (let attempt = 1; ; attempt += 1) {
const backoff = () => new Promise((resolve) => setTimeout(resolve, 2 ** attempt * 100));
let response;
try {
response = await fetch(`${process.env.TETHER_BASE_URL}${path}`, {
...options,
signal: AbortSignal.timeout(TIMEOUT_MS),
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.TETHER_TOKEN}`,
...(options.headers || {}),
},
});
} catch (error) {
// Only timeouts and network errors reach here, and only those retry.
if (attempt >= maxAttempts) throw error;
await backoff();
continue;
}
// 5xx is the only status worth retrying; a 4xx will not change.
if (response.status >= 500 && attempt < maxAttempts) {
await backoff();
continue;
}
// Thrown outside the catch above, so a 401 or 404 fails on the first try.
if (!response.ok) {
throw new Error(`API request failed: ${response.status}`);
}
return response.json();
}
}Next
- See Authentication for token acquisition.
- Use the API reference for exact payload schemas.