Choosing an API style is one of those decisions that feels permanent and is, in practice, less important than the conventions you build around it. Teams that struggle with APIs rarely struggle because they picked REST over GraphQL. They struggle because pagination is inconsistent, errors are unparseable, versioning is an afterthought and nobody can tell what the contract actually is.
This article compares the three styles most teams consider in 2026, then spends most of its time on the cross-cutting decisions that determine whether an API stays pleasant to use after two years and twenty consumers.
The three contenders
REST over HTTP and JSON
REST, in the pragmatic sense most teams use, means resources identified by URLs, standard HTTP verbs, status codes, and JSON bodies. Its strengths are universality and the HTTP ecosystem: caches, CDNs, proxies, browser tooling, curl, and every language’s HTTP client. It is the default for public APIs and for anything consumed by teams you do not control.
Weaknesses show up with deeply related data. A mobile screen that needs a user, their last five orders and the items in each might require three round trips or a bespoke endpoint. Over-fetching and under-fetching are real, although often overstated.
GraphQL
GraphQL exposes a typed schema and lets clients specify exactly the fields they want in a single request. It shines when you have many different clients with different data needs, such as a web app, two mobile apps and partner integrations, all reading from a rich graph of entities.
The costs are well known. Caching becomes harder because almost every request is a POST to a single URL. Query complexity must be bounded or a single client can request an expensive nested query. The N+1 problem moves to the resolver layer and requires batching tools such as DataLoader. Authorization has to be enforced per field or per resolver, not per route. These are manageable, but they are real engineering work.
tRPC
tRPC is different in kind. It is not a protocol you publish; it is a way to call server functions from a TypeScript client with end-to-end type inference and no code generation. If your backend and frontend live in one TypeScript monorepo, the productivity is hard to beat: change a procedure’s return type and the client fails to compile.
The trade-off is coupling. tRPC assumes a TypeScript client that shares types with the server. It is a poor fit for public APIs, non-TypeScript clients, or organizations where the mobile team uses Swift and Kotlin. You can generate an OpenAPI description from tRPC routers with community tooling, but at that point you are partly rebuilding REST.
A decision matrix
| Situation | Best fit | Why |
|---|---|---|
| Public API for third parties | REST + OpenAPI | Universal tooling, cacheable, stable contract |
| One TypeScript monorepo, web only | tRPC | Zero-boilerplate type safety |
| Many client types, rich relational data | GraphQL | Client-driven queries, one schema |
| Internal service-to-service, high throughput | REST or gRPC | Simple, efficient, strongly typed with schemas |
| Mobile apps with strict bandwidth needs | GraphQL or purpose-built REST endpoints | Control over payload size |
| Small team, simple CRUD | REST | Least moving parts |
Notice that the answer is rarely exclusive. A common and healthy pattern is REST for the public surface and webhooks, tRPC for the internal admin dashboard, and GraphQL only if a specific client genuinely needs it. Avoid adopting a style because it is fashionable; adopt it because a named consumer benefits.

Resource modeling and naming
For REST, a few conventions pay off immediately:
- Use plural nouns for collections:
/invoices,/invoices/{id}. - Model sub-resources only one level deep:
/invoices/{id}/lines. Deeper nesting becomes unreadable; use query filters instead. - Use
POSTfor creation,PUTfor full replacement,PATCHfor partial updates,DELETEfor removal. KeepGETsafe and idempotent. - For actions that do not map to CRUD, use a sub-resource verb deliberately:
POST /invoices/{id}/send. This is better than contorting state changes into fake updates. - Use ISO 8601 timestamps in UTC, and represent money as integer minor units plus a currency code, never floating point.
Idempotency deserves special attention. Any POST that creates money movement or an external side effect should accept an Idempotency-Key header, store the key with the result for at least 24 hours, and return the same response on retry. Networks fail, mobile clients retry, and without idempotency you will double charge someone.
Pagination
Pagination is where many APIs quietly rot. The two main approaches:
- Offset pagination (
?page=3&per_page=50): simple, supports jumping to a page, but slow on large tables because the database must skip rows, and inconsistent when rows are inserted during traversal. - Cursor pagination (
?after=eyJpZCI6MTIzfQ&limit=50): the server returns an opaque cursor encoding the position of the last item, usually based on an indexed, stable sort key. It is consistent under concurrent writes and fast at any depth.
For anything that can grow beyond a few thousand rows, default to cursor pagination. Keep the cursor opaque (base64 of a small JSON blob is fine) so you can change its internals. Return a response envelope that makes continuation obvious:
{
"data": [{ "id": "inv_123", "total": 12900, "currency": "USD" }],
"page": {
"next_cursor": "eyJpZCI6Imludl8xMjMifQ",
"has_more": true
}
}
Set a maximum limit (100 is common) and a sensible default (25 or 50). Do not return total counts by default; COUNT(*) on large tables is expensive. Offer it as an opt-in parameter if consumers truly need it.
GraphQL has a standard answer in the Relay connection specification, with edges, node, pageInfo and cursors. It is verbose but predictable, and client libraries understand it.
Errors that clients can act on
An error response has two audiences: a human reading logs and a program deciding what to do. Serve both. The IETF’s Problem Details format (RFC 9457, which updated RFC 7807) gives a standard JSON shape:
{
"type": "https://api.example.com/errors/insufficient-funds",
"title": "Insufficient funds",
"status": 422,
"detail": "Balance is 1000 cents, transfer requires 2500.",
"code": "insufficient_funds",
"request_id": "req_8f2c1a"
}
Guidelines that hold across styles:
- Use HTTP status codes correctly: 400 for malformed input, 401 for missing authentication, 403 for lacking permission, 404 for not found, 409 for conflicts, 422 for semantic validation failures, 429 for rate limits, 5xx for server faults.
- Provide a stable, machine-readable
codethat never changes, separate from the human-readable message, which you may reword or translate. - For validation errors, return a list of field-level problems with JSON pointers so a form can highlight the right inputs.
- Always include a
request_idthat also appears in your logs. Support teams will thank you. - Never leak stack traces, SQL or internal hostnames.
GraphQL complicates this because it returns HTTP 200 with an errors array, even for failures. Put your stable error code in extensions.code, and make sure monitoring inspects the body, not only the status code. With tRPC, use its typed error codes and map them to HTTP statuses consistently.
Versioning and evolution
The cheapest versioning strategy is not needing a new version. Design for additive change:
- Adding optional request fields and new response fields is safe if clients ignore unknown fields. State this in your documentation as a requirement.
- Never change the meaning of an existing field. Add a new one and deprecate the old.
- Enum values are a trap: adding a new value can break clients with exhaustive switches. Document that clients must handle unknown values.
When you must make a breaking change, REST teams usually choose between URL versioning (/v2/invoices) and header or media-type versioning. URL versioning is more visible, easier to route and debug, and works in browsers. Header versioning is cleaner in theory but harder to test casually. For most teams, URL versioning with a major number only is the pragmatic choice.
Some APIs, including Stripe’s, pin each account to the version active when they signed up and let them upgrade deliberately, translating responses through a chain of version transforms. It is powerful and expensive; only attempt it if you have many external consumers and the engineering capacity.
GraphQL’s philosophy is continuous evolution: deprecate fields with the @deprecated directive, monitor field usage, and remove after consumers have migrated. That works well when you can observe usage per field, which you should instrument from day one. tRPC inside a monorepo sidesteps versioning because client and server deploy together, but mobile apps in the wild can lag server deployments by months, so keep the contract backward compatible for any non-web client.
Publish a deprecation policy: how much notice you give (six months is typical for external APIs), how you signal it (Deprecation and Sunset response headers, changelog, emails), and how you measure remaining usage.
Contracts, OpenAPI and testing
A contract that exists only in someone’s head is not a contract. For REST, OpenAPI 3.1 is the standard description format, and it earns its keep through the things you can derive from it:
- Interactive documentation for consumers.
- Generated client SDKs and server stubs, which remove a whole category of manual mapping bugs.
- Request and response validation middleware that rejects malformed payloads before your business logic runs.
- Contract tests that fail CI when an implementation drifts from the spec.
- Breaking-change detection, by diffing the spec between the main branch and a pull request using a tool such as
oasdiff.
There are two workflows. Spec-first means you write the OpenAPI document, review it like code, then implement it. Code-first means you annotate handlers and generate the spec. Spec-first produces better designs because the review happens before the code exists; code-first is faster and stays in sync more reliably. Choose one, and enforce it in CI so the spec and the code cannot diverge. See the OpenAPI Initiative documentation for the specification details.
For GraphQL, the schema is the contract, and tooling such as schema registries and linting rules can catch breaking changes. For tRPC, the TypeScript compiler is your contract test inside the monorepo.
Security and operations
Whatever style you choose, certain practices are non-negotiable:
- Authenticate with short-lived tokens, authorize on every request at the resource level, and test for broken object-level authorization, which consistently tops API security risk lists.
- Rate limit per credential and per IP, and return
429with aRetry-Afterheader. - Set request size limits and timeouts. For GraphQL, add query depth and cost limits, and consider persisted queries for first-party clients so arbitrary queries cannot be sent in production.
- Log request IDs, latency and status per endpoint, and alert on error-rate and p95 latency changes.
- Make list endpoints filterable and sortable only by indexed fields; otherwise a harmless-looking parameter becomes a denial of service.
Key takeaways
- Pick the style by consumer: REST plus OpenAPI for public and heterogeneous clients, tRPC for a single TypeScript codebase, GraphQL when many clients need flexible reads of a rich graph.
- Default to cursor pagination with an opaque cursor and a hard maximum page size.
- Standardize errors on Problem Details with stable machine codes and a request ID.
- Design for additive evolution, publish a deprecation policy, and use URL versioning only for genuinely breaking changes.
- Treat the contract as an artifact: write or generate an OpenAPI spec, validate against it, and diff it in CI.
- Require idempotency keys for any request that moves money or triggers external side effects.

