Prompt
What should I use for edge-based APIs on web and mobile?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
For edge-based APIs that need to work well for both web and mobile, the safest default is:
Recommended stack
HTTP/JSON over REST for the API shape, deployed behind an edge runtime / CDN, with:
- JWT or opaque access tokens for auth
- Cursor-based pagination
- Idempotency keys for writes
- Versioning in the URL or headers
- Compression + caching at the edge
- Optional SSE/WebSocket only for realtime needs
Why this is usually the best choice
- Web and mobile both support it easily
- Works well with CDNs and edge workers
- Easy to debug, cache, secure, and observe
- Plays nicely with offline/retry behavior on mobile
- Less operational complexity than custom protocols
Good choices by use case
1) Standard CRUD / business APIs
Use:
- REST + JSON
- Edge functions for lightweight auth, routing, personalization, and aggregation
Best when:
- You need broad compatibility
- Your clients are web + iOS + Android
- You want simple caching and observability
2) Realtime updates
Use:
- SSE for server-to-client streaming updates
- WebSockets if you need bidirectional realtime interaction
Best when:
- Notifications, live dashboards, presence, chat, collaborative editing
3) High-performance internal/mobile transport
Use:
- gRPC only if you control most clients and need strong contracts/performance
Caveat:
- Web support is more awkward unless you use gRPC-Web
- Less cache-friendly at the edge than HTTP/JSON
Practical recommendation
If you’re starting today:
- Public API: REST + JSON
- Realtime: SSE first, WebSockets if needed
- Edge layer: Cloudflare Workers / Vercel Edge / Fastly Compute / AWS Lambda@Edge
- Data access: keep edge logic thin; do auth, caching, routing, and response shaping at the edge
If you want the shortest answer
Use REST over HTTP/JSON, augmented with SSE/WebSockets for realtime, and deploy the API logic on an edge runtime.
If you want, I can also give you:
- a decision matrix comparing REST vs GraphQL vs gRPC vs tRPC for edge APIs, or
- a reference architecture for web + iOS + Android with edge caching and auth.