A Practical Guide to API Design for Front Ends
Shaping the interface between a server and the browser so the client can get what it needs in as few round trips as possible, without being told about the database.
On this page
At a glance
- Common styles REST, GraphQL and remote procedure call
- Request waterfall when one response is needed to know what to request next
- Pagination cursor-based is more stable than offset over changing data
- Versioning needed the moment a second consumer exists
- Error contract machine-readable codes, not prose the client has to parse
Why it matters
Why it matters: An API designed around storage rather than use forces the front end into waterfalls of dependent requests, and every one of those is a delay the user feels.
Best practice
- Design endpoints around what a screen needs rather than around a table
- Return errors in a consistent, documented shape with a stable code
- Paginate anything that can grow without bound
- Version before the second consumer arrives, not after it breaks
- Document with real examples, including the failure cases
Common pitfalls
Watch out for:
- Exposing the database schema as the public contract
- Chatty endpoints that force the client into a waterfall
- Breaking changes shipped without a version
- Errors that are only readable by a human reading a stack trace
When to call in a specialist
Bottom line Bring in help when a screen needs half a dozen sequential requests to render, when a change to the API keeps breaking a client, or when mobile and web need different shapes of the same data.
Where this comes from
- MDN Web Docs — HTTP and the Fetch API
- Laravel Documentation — API resources and routing
- Stripe Documentation — API design conventions
The figures and practices above come from the sources listed.
Working on something like this?
We take on Web Design & Development work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.
Where to go next
Spotted something wrong? Report an error on this page. We correct on the page and say what changed.