APIs Are Your Product's Interface
Whether you are building a SaaS platform, a mobile application, or integrating with third-party systems, your API is the contract between your backend and the outside world. A well-designed API is intuitive, consistent, versioned, and documented. At Nexis Limited, we design REST APIs for most of our products and have evaluated GraphQL for specific use cases.
REST: The Established Standard
REST (Representational State Transfer) uses standard HTTP methods and URL structures to represent resources. Its simplicity, cacheability, and universal tooling support make it the default choice for most APIs.
REST Best Practices
- Use nouns, not verbs: /api/users rather than /api/getUsers. The HTTP method (GET, POST, PUT, DELETE) indicates the action.
- Consistent naming: Use plural nouns (users, orders, shipments) and kebab-case for multi-word resources.
- Proper status codes: Return 201 for created resources, 204 for successful deletions, 400 for validation errors, 401 for authentication failures, 404 for missing resources.
- Pagination: All list endpoints should support pagination via cursor-based or offset-based parameters.
- Filtering and sorting: Provide query parameters for filtering (status=active) and sorting (sort=created_at&order=desc).
- Versioning: Use URL path versioning (/api/v1/) or header-based versioning to evolve your API without breaking existing clients.
GraphQL: When REST Falls Short
GraphQL excels when clients need flexible data fetching — requesting exactly the fields they need, combining data from multiple resources in a single request, and avoiding over-fetching or under-fetching. It is particularly valuable for mobile applications with bandwidth constraints and for dashboards that aggregate data from many sources.
GraphQL Considerations
- Complexity: GraphQL shifts complexity from the client to the server. Resolvers, N+1 query problems, and query depth limiting require careful engineering.
- Caching: HTTP caching is straightforward with REST (GET requests are cacheable by URL). GraphQL uses POST for all queries, making HTTP-level caching impractical without specialized tools.
- Tooling: While GraphQL tooling has matured significantly (Apollo, Relay, urql), REST's tooling ecosystem remains broader and more battle-tested.
Our Recommendation
For most applications, start with REST. It is simpler to build, simpler to cache, simpler to monitor, and most developers are familiar with it. Consider GraphQL if you have diverse clients with different data requirements, need real-time subscriptions, or are building a developer platform where API flexibility is a competitive advantage.
Documentation Is Non-Negotiable
Regardless of API style, documentation must be a first-class concern. For REST, use OpenAPI (Swagger) specifications. For GraphQL, the schema itself serves as documentation, supplemented by descriptions on types and fields. At Nexis Limited, we auto-generate API documentation from code annotations and keep it versioned alongside the codebase.
Conclusion
The best API is one that serves its consumers effectively. REST remains the pragmatic default for most applications. GraphQL is a powerful tool for specific scenarios. Invest in documentation, consistency, and versioning regardless of which style you choose.
Building an API-driven product? Consult with our backend team on design and architecture.