Digital Infohub
Engineering · Tech Topics

APIs Explained: REST, GraphQL and Good Design

An API is a contract that lets one piece of software ask another for data or an action without knowing how the other is built.

Every app that shows a map, takes a payment or sends a message is calling an API. The interface hides implementation details, so the provider can change internals without breaking every client.

Good APIs are predictable. Names, error formats and pagination behave the same way everywhere, and a developer can guess the right call after reading one example.

REST, GraphQL and gRPC

REST models resources with HTTP verbs and URLs. It is simple, cacheable and universally understood, which is why it dominates public APIs. GraphQL exposes a typed schema and lets the client ask for exactly the fields it needs, which suits complex frontends with varied data requirements.

gRPC uses binary messages over HTTP/2 for fast, strongly typed service-to-service calls. It is common inside microservice architectures where performance and schema enforcement matter more than browser compatibility.

Authentication and authorisation

Public APIs use keys to identify a project, OAuth for delegated access on a user's behalf, and short-lived tokens for sensitive operations. Keys must be treated as secrets and rotated when exposed.

Authorisation is separate from authentication. A valid token still needs a permission check on every action, and object-level checks must prevent one customer from reading another's data by changing an identifier.

Never ship a secret API key in a mobile app or browser bundle. Anything the client can read, an attacker can read too.

Design rules worth following

Return consistent shapes, use clear status codes, and paginate everything that could grow. Rate-limit with informative headers, document errors with stable codes, and make idempotency explicit so a retried payment does not charge twice.

Version deliberately. Additive changes are usually safe, but removing or renaming a field breaks clients that you cannot see. Deprecation notices with a migration window are cheaper than an outage.

Using someone else's API

Read the rate limits and error codes before writing code, and implement retries with exponential backoff plus jitter. Cache responses where the provider allows it, and design so that an unavailable third party degrades gracefully instead of taking your product down.

Check the provider's deprecation policy and status history. A service that changes behaviour without notice is a liability no matter how good the documentation looks.

Key facts at a glance

An API is a contract, so stability is a feature.
REST dominates public APIs; gRPC dominates internal service calls.
Client-side keys are public by definition and cannot hold secrets.
Retries need idempotency or they duplicate side effects.

Frequently asked questions

What does API stand for?

Application Programming Interface: a defined way for two programs to exchange requests and data without exposing their internal implementation.

Is GraphQL better than REST?

Neither is universally better. GraphQL reduces over-fetching for complex clients but adds caching, query-cost and tooling complexity. REST is simpler to cache and operate.

How do I keep an API key safe in a website?

Do not put it in the website. Route requests through your own backend or a serverless function that holds the key privately and applies its own access checks.

Further reading: Wikipedia — APIs

Keep exploring Digital Infohub