Skip to content

Commit 841e60f

Browse files
Mlaz-codeclaude
andauthored
docs(api-reference): document connection reuse + HTTP/3 + X-Cache-Status (#228)
Adds a "Connection Reuse" section to the API reference overview, plus two new rows in the Standard Response Headers table for `X-Cache-Status` and `Alt-Svc`. For polling clients, TLS handshake (150-200ms on a fresh connection) dominates per-request latency on api.sharpapi.io — the server itself returns in ~40-50ms TTFB. Reusing a TLS connection collapses the cost. The new section explains keep-alive defaults, HTTP/2 multiplexing, HTTP/3 via Alt-Svc, and points serverless / cold-start callers at `/api/v1/stream` for real-time data. Closes Mlaz-code/sharp-api-go#113. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8c298b6 commit 841e60f

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

content/en/api-reference/overview.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,45 @@ Every API response includes these headers:
229229
| `X-RateLimit-Reset` | `1705804800` | Unix timestamp when the rate limit resets |
230230
| `X-Data-Delay` | `0` | Data delay in seconds (`60` for Free, `0` for paid tiers) |
231231
| `X-Request-Id` | `req_a1b2c3d4` | Unique request identifier for debugging and support |
232+
| `X-Cache-Status` | `HIT` | Edge-cache state for this response (`HIT`, `MISS`, `STALE`, `BYPASS`). `STALE` means the edge briefly served slightly outdated content while revalidating against the origin — expected during transient origin slowness, not an error |
233+
| `Alt-Svc` | `h3=":443"; ma=86400` | Indicates HTTP/3 (QUIC) is available on this host. Clients that opt in skip the TCP + TLS handshake on subsequent connections — see [Connection Reuse](#connection-reuse) below |
232234

233235
<Callout type="info">
234236
Include the `X-Request-Id` value when contacting support about a specific request.
235237
</Callout>
236238

239+
## Connection Reuse
240+
241+
For polling clients, the dominant cost on a *fresh* connection to `api.sharpapi.io` is the TLS handshake — typically 150–200 ms — not the API server itself, which returns in ~40–50 ms once TCP + TLS are up. Reusing a single TLS connection across requests collapses subsequent calls to roughly the server-side TTFB.
242+
243+
```bash
244+
# Fresh connection — first request pays full TCP + TLS:
245+
curl -o /dev/null -s \
246+
-w "ssl=%{time_appconnect}s ttfb=%{time_starttransfer}s total=%{time_total}s\n" \
247+
-H "X-API-Key: $SHARPAPI_KEY" \
248+
https://api.sharpapi.io/api/v1/gamestate/baseball
249+
# → ssl=0.16s ttfb=0.20s total=0.20s
250+
251+
# Two URLs in one curl call — the second reuses the open connection:
252+
curl -o /dev/null -s \
253+
-w "ssl=%{time_appconnect}s ttfb=%{time_starttransfer}s total=%{time_total}s\n" \
254+
-H "X-API-Key: $SHARPAPI_KEY" \
255+
https://api.sharpapi.io/api/v1/gamestate/baseball \
256+
https://api.sharpapi.io/api/v1/gamestate/tennis
257+
# → ssl=0.00s ttfb=0.04s total=0.04s
258+
```
259+
260+
### Recommendations
261+
262+
- **HTTP/1.1 keep-alive is the default** in `curl`, Python `httpx` / `requests.Session()`, `aiohttp`, Node `fetch` / `axios` / `undici`, Go `http.Client`, OkHttp, and most other modern clients. Reuse a single client/session across calls — don't construct a new client per request.
263+
- **HTTP/2 connection coalescing** multiplexes many concurrent requests over one connection to the same host. Enabled by default in HTTP/2-capable clients.
264+
- **HTTP/3 (QUIC)** is offered via `Alt-Svc: h3=":443"`. Clients that opt in (`curl --http3`, `httpx[http2,http3]`, Node `undici` with `allowH2: true`) skip the TCP handshake entirely on subsequent connections. Worthwhile for cold-start workloads such as serverless functions.
265+
- **For real-time data, use streaming.** The [`/api/v1/stream`](/en/api-reference/stream) endpoint keeps a single connection open and pushes deltas as they happen — no per-request handshake at all.
266+
267+
<Callout type="info">
268+
For a polling client hitting `/api/v1/odds` once per second, the TLS cost amortizes to ~0 after the first request. The 150 ms handshake matters most for serverless / short-lived clients that close the connection between calls.
269+
</Callout>
270+
237271
## Tier Comparison
238272

239273
| Feature | Free | Hobby | Pro | Sharp | Enterprise |

0 commit comments

Comments
 (0)