WEB API's Lesson 3 – API Types | Dataplexa
Web APIs · Lesson 3

API Types

Master the four main API types that power modern software development

Twitter's API handles 500 million requests daily. Stripe processes billions in payments through theirs. GitHub's API powers thousands of developer tools. But here's what most people miss: these companies use different API types for different jobs.

Not all APIs work the same way. Some send data when you ask. Others push updates the moment something changes. Some handle simple requests. Others orchestrate complex workflows across dozens of services.

Understanding API types transforms you from someone who just calls endpoints to someone who picks the right tool for each problem. The APIForge Backend team learned this when their notification system crashed under load — they were using the wrong API type for real-time updates.

The Four Core API Types

Modern software runs on four main API types: REST, GraphQL, WebSocket, and RPC. Each solves different problems.

REST dominates web development because it maps cleanly to HTTP. GraphQL gives clients precise control over data fetching. WebSocket enables real-time bidirectional communication. RPC focuses on calling remote functions like local ones.

The choice between them shapes your entire application architecture. Pick REST for standard CRUD operations. Choose GraphQL when different clients need different data shapes. Use WebSocket for live updates. Reach for RPC when you need to call complex remote procedures.

1
Client sends HTTP request to REST endpoint
2
Server processes request based on HTTP method and URL
3
Database query executes and returns data
4
Server returns JSON response with appropriate status code

REST APIs: The Web Standard

REST (Representational State Transfer) became the dominant API style because it works naturally with HTTP. Every URL represents a resource. Every HTTP method performs a specific action.

A REST API treats your application data as resources accessible through predictable URLs. /users/123 always refers to user 123. GET retrieves data. POST creates new resources.

The APIForge Backend team chose REST for their user management system because it matched how their frontend developers think about data. Each screen corresponds to resources. Each user action maps to HTTP methods. The mental model stays consistent from browser to database.

REST Characteristics

REST APIs are stateless (each request contains all needed information), cacheable (responses can be stored for reuse), and use standard HTTP status codes to indicate success or failure. They work with existing web infrastructure without special protocols.

Stripe's payment API exemplifies REST design. POST /charges creates payments. GET /charges/ch_1234 retrieves payment details. POST /refunds processes returns. Each endpoint does one thing well.

REST shines for CRUD operations (Create, Read, Update, Delete) on clearly defined resources. It struggles when you need to fetch complex, interconnected data in a single request or when different clients need drastically different data shapes.

GraphQL: Query Exactly What You Need

GraphQL solves REST's over-fetching and under-fetching problems by letting clients specify exactly what data they want. Instead of multiple API calls, you write one query describing your exact needs.

Facebook created GraphQL because their mobile app needed different data than their web app for the same features. REST APIs forced them to either create separate endpoints for each client or accept wasteful data transfers. GraphQL gave clients control over response shape.

The APIForge Frontend team pushed for GraphQL when they realized their dashboard was making 12 REST API calls to load one screen. Users on slow connections waited 8 seconds for scattered data to assemble. GraphQL collapsed those 12 calls into one targeted query.

REST Approach

Multiple endpoints, fixed responses, possible over-fetching of unused data

GraphQL Query

Single endpoint, custom queries, exact data specification per request

Strongly Typed

Schema defines exact data structure, enables powerful developer tools and validation

Real-time Subscriptions

Built-in support for live updates when data changes on the server

GitHub's API demonstrates GraphQL's power. Their REST API required multiple requests to get a repository's issues, contributors, and recent commits. Their GraphQL API lets you fetch all three in one query, specifying exactly which fields you need from each.

GraphQL excels when different clients need different data shapes from the same backend. Mobile apps want minimal data for battery life. Desktop apps can handle richer responses. GraphQL serves both without separate endpoints.

The trade-off comes in complexity. GraphQL requires more sophisticated caching strategies than REST. Query performance depends on how well your resolvers handle nested data fetching. Simple CRUD operations often work better with straightforward REST endpoints.

WebSocket APIs: Real-Time Bidirectional Communication

WebSocket APIs break the request-response cycle by maintaining persistent connections between client and server. Both sides can send messages at any time, enabling true real-time applications.

Traditional HTTP APIs work like postal mail — you send a request and wait for a response. WebSocket APIs work like phone calls — both sides can talk whenever they need to. This fundamental difference makes WebSockets perfect for chat applications, live trading systems, and collaborative editing tools.

The APIForge Product team discovered WebSocket's importance when building their real-time collaboration features. REST APIs forced their document editor to poll for changes every 500 milliseconds. Users saw other people's edits with noticeable delays, and the constant polling hammered their servers.

WebSocket Connection Flow

Client initiates HTTP request with Upgrade header, server responds with 101 status code switching protocols, connection upgrades to WebSocket for persistent bidirectional messaging until either side closes the connection.

Slack's messaging system showcases WebSocket APIs in production. When someone sends a message, it instantly appears for all channel members without page refreshes or polling. Typing indicators, online status updates, and emoji reactions all flow through the same persistent connection.

WebSocket APIs excel for applications requiring instant updates, live data streams, or bidirectional communication. Financial trading platforms use them for real-time price feeds. Multiplayer games rely on them for low-latency player actions. Live streaming services use them for chat overlays.

The complexity comes in connection management. Unlike HTTP requests that complete and close, WebSocket connections stay open until explicitly closed. Servers must handle connection scaling, message queuing, and graceful reconnection when networks hiccup.

RPC APIs: Remote Procedure Calls

RPC (Remote Procedure Call) APIs make calling functions on remote servers feel like calling local functions. Instead of thinking about HTTP methods and resources, you think about function calls and parameters.

RPC focuses on actions rather than resources. Where REST might use POST /orders with a JSON payload, RPC uses createOrder(userId, items, shippingAddress). The mental model shifts from manipulating resources to calling remote functions.

The APIForge Backend team chose RPC for their payment processing integration because it matched their internal service architecture. Their billing service needed to call complex procedures like calculateTaxWithDiscounts() and processRefundWithPartialItems() that didn't map cleanly to REST resources.

RPC Type Protocol Best For Example Use
JSON-RPC HTTP/WebSocket Web applications Cryptocurrency wallets
gRPC HTTP/2 Microservices Google internal services
XML-RPC HTTP Legacy systems WordPress ping services

gRPC (Google RPC) represents modern RPC design. It uses Protocol Buffers for efficient serialization, supports multiple programming languages, and provides features like streaming and authentication. Netflix uses gRPC for internal service communication because it handles high-throughput service-to-service calls efficiently.

RPC APIs work best for internal service communication and systems where you're calling complex business logic rather than manipulating data resources. They struggle with caching (since function calls are less predictable than resource requests) and don't map as naturally to HTTP semantics.

Choosing the Right API Type

The best API type depends on your specific use case, not abstract architectural preferences. Each type evolved to solve particular problems that others handle poorly.

Consider data patterns first. If you're building a typical web application with users, posts, and comments, REST's resource-based thinking matches your domain naturally. If you have complex, interconnected data that different clients consume differently, GraphQL's flexible querying shines.

Think about communication patterns next. Request-response interactions suit REST and GraphQL perfectly. Real-time bidirectional communication demands WebSocket APIs. Complex business operations that don't map to CRUD work better as RPC function calls.

When to Choose REST

Standard CRUD operations on well-defined resources

Caching is important for performance

Team familiarity with HTTP semantics

When to Choose GraphQL

Multiple clients need different data shapes

Complex, interconnected data relationships

Strong typing and developer tools matter

Performance requirements matter significantly. REST APIs cache easily but may require multiple requests for complex data. GraphQL reduces requests but makes caching harder. WebSocket APIs provide minimal latency but consume more server resources. RPC APIs optimize for service-to-service communication efficiency.

Team expertise influences the decision too. REST builds on familiar HTTP concepts most developers understand. GraphQL requires learning new query languages and caching strategies. WebSocket APIs need connection management skills. RPC APIs work best when teams already think in terms of remote function calls.

Many successful applications combine multiple API types. Slack uses REST for basic operations, WebSocket for real-time messaging, and internal RPC for service communication. The key is matching each communication pattern to the appropriate API type rather than forcing everything through one approach.

Real-World API Type Selection

Successful companies often mix API types strategically rather than committing to one approach. Understanding how industry leaders combine different API types reveals practical decision-making patterns.

Shopify exposes REST APIs for most merchant operations, GraphQL for their Storefront API (where mobile and web apps need different product data), and WebSocket for real-time order notifications. Each API type handles what it does best without forcing compromises.

The APIForge DevOps team learned this lesson when designing their monitoring system. They used REST for configuration management (natural CRUD operations on servers and services), WebSocket for live log streaming (real-time data flows), and internal RPC for triggering deployment procedures (complex business logic).

Common Mistake

Forcing all communication through one API type because it's "simpler" or "more consistent"

Better Approach

Match each communication pattern to the API type that handles it most naturally and efficiently

Consider latency sensitivity when choosing API types. Financial trading systems use WebSocket APIs for price updates (milliseconds matter), REST for account management (occasional operations), and RPC for complex risk calculations (business logic doesn't map to resources).

Scaling characteristics differ between API types too. REST APIs scale horizontally easily because they're stateless. WebSocket APIs require more sophisticated load balancing because connections are stateful. GraphQL APIs need careful query analysis to prevent expensive operations. RPC APIs optimize for service-to-service efficiency over general web access.

The most important insight from studying real-world API choices: successful systems optimize for their primary use cases rather than trying to be perfect for all scenarios. Twitter's API prioritizes reading tweets (REST works great) over real-time updates (which they handle separately through streaming APIs).

Quiz

1. The APIForge Frontend team is building a dashboard that shows user profiles, recent activities, and team memberships. Currently, they make separate REST API calls for each data type, causing slow page loads. Which API type would best solve this problem and why?

2. APIForge is building a collaborative code editor where multiple developers can edit the same file simultaneously. They need to show real-time cursor positions, live typing, and instant saves. Which API type best handles this requirement?

3. APIForge needs to build a system with three components: user account management (standard CRUD), real-time notification delivery, and complex billing calculations between internal services. What's the best architectural approach?

Up Next
Client–Server Model
Understand how applications communicate across networks and why this architecture dominates modern software