REST API vs HTTP API vs WebSocket API
Understand the tradeoffs between REST API (feature-rich), HTTP API (low-latency, low-cost), and WebSocket API (bidirectional) and choose appropriately.
REST API vs HTTP API vs WebSocket API is a free AWS Solutions Architect lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why API Gateway Exists
Amazon API Gateway is a fully managed service that lets you create, publish, secure, and monitor APIs at any scale. It acts as the front door for your backend services—Lambda functions, EC2 instances, HTTP backends, or any AWS service. API Gateway handles traffic management, authorisation, throttling, monitoring, and API versioning, so your backend can focus on business logic rather than API infrastructure concerns.
REST API: Feature-Rich Traditional API
REST API (original API Gateway product) provides the widest feature set: request/response transformation with mapping templates, per-method throttling, usage plans with API keys, response caching, WAF integration, X-Ray tracing, resource policies, and client certificate mutual TLS. REST APIs support all integration types: Lambda, HTTP, AWS service, Mock, and Lambda Proxy. Use REST API when you need advanced features like transformation, caching, or usage plans.
HTTP API: Low-Latency Low-Cost Alternative
HTTP API was designed as a simpler, cheaper, faster alternative to REST API. It supports Lambda proxy and HTTP proxy integrations only—no AWS service integrations, no mock. Key advantages: up to 70% lower cost than REST API, lower latency, native OIDC and OAuth 2.0 JWT authorisation built in (no Lambda authoriser needed for common auth scenarios), and automatic deployment. If you don't need caching, usage plans, or request/response transformation, HTTP API is the better choice.
# Create a simple HTTP API
aws apigatewayv2 create-api \
--name 'MyHttpAPI' \
--protocol-type HTTP \
--target 'arn:aws:lambda:us-east-1:123456789012:function:MyLambda'WebSocket API: Bidirectional Real-Time Communication
WebSocket API maintains persistent, bidirectional connections between clients and the server. Unlike HTTP (request-response), WebSocket allows the server to push messages to connected clients at any time without the client polling. API Gateway manages WebSocket connections and routes messages to Lambda functions based on route expressions. Use WebSocket APIs for real-time applications: chat apps, live dashboards, collaborative editing, gaming, stock tickers.
WebSocket Routes and Connection Management
WebSocket APIs have three built-in routes: $connect (triggered when a client opens a connection), $disconnect (triggered when a connection closes), and $default (catches unmatched messages). You can add custom routes like sendmessage mapped to specific Lambda functions. Use the @connections management API to send messages back to connected clients from your Lambda function using the client's connection ID.
# Send a message to a specific WebSocket client from Lambda
import boto3
gw_client = boto3.client(
'apigatewaymanagementapi',
endpoint_url='https://abc123.execute-api.us-east-1.amazonaws.com/prod'
)
def lambda_handler(event, context):
connection_id = event['requestContext']['connectionId']
gw_client.post_to_connection(
Data='{"type": "message", "text": "Hello!"}',
ConnectionId=connection_id
)Feature Comparison: REST vs HTTP vs WebSocket
Key differences at a glance:
- REST API: full features (caching, usage plans, transforms, WAF), higher cost, supports all integration types
- HTTP API: Lambda/HTTP proxy only, 70% cheaper, built-in JWT auth, lower latency, no caching or usage plans
- WebSocket API: persistent bidirectional connections, server-push capable, billed per million messages and per minute of connection time
For the SAA-C03 exam: HTTP questions without real-time or advanced features → HTTP API. Real-time push → WebSocket. Complex API features → REST API.
Stages and Deployments
API Gateway APIs are deployed to stages (e.g., dev, staging, prod). Each stage has its own URL, throttling settings, and can reference a specific deployment snapshot. Use stage variables (similar to environment variables) to parameterise backend endpoints per stage—for example, point the dev stage to a dev Lambda alias and prod to the prod alias without duplicating API configuration.
# REST API: create a deployment and stage
aws apigateway create-deployment \
--rest-api-id 'abc123' \
--stage-name 'prod'
# Set stage variable
aws apigateway update-stage \
--rest-api-id 'abc123' \
--stage-name 'prod' \
--patch-operations 'op=replace,path=/variables/lambdaAlias,value=prod'Custom Domain Names and Base Path Mappings
By default API Gateway URLs contain the API ID (e.g., abc123.execute-api.us-east-1.amazonaws.com). For production use, create a custom domain name backed by an ACM certificate and map it to your API and stage. Use base path mappings to host multiple APIs under one domain (e.g., api.example.com/orders → Orders API, api.example.com/users → Users API). Custom domain names require a Route 53 alias record pointing to the API Gateway endpoint.
Edge-Optimised vs Regional vs Private APIs
REST APIs can be deployed in three endpoint types: Edge-Optimised (CloudFront front-end for global distribution, default), Regional (no CloudFront, lower latency for same-region clients or when you add your own CloudFront), and Private (only accessible from within your VPC via an interface VPC endpoint, for internal microservices). HTTP APIs support Edge-Optimised and Regional. WebSocket APIs support Regional and Private. Choose Regional for APIs consumed from the same region or when using custom CloudFront distributions.
Canary Deployments with API Gateway
API Gateway REST APIs support canary deployments on a stage. You can route a percentage of traffic to a canary deployment (new version) while the rest goes to the production deployment. Monitor error rates and latency on the canary; if stable, promote it to 100%. If problems arise, roll back by setting canary weight to 0. This is analogous to Lambda alias weighted routing and allows safe, gradual API updates without blue/green environment switching.
Choosing the Right API Type for the Exam
SAA-C03 exam question keywords to identify API type: 'cost-effective simple API' → HTTP API; 'real-time bidirectional' or 'server push' or 'chat' → WebSocket API; 'request transformation', 'usage plans', 'API key throttling', 'response caching' → REST API. When the question is simply 'expose Lambda as an HTTP endpoint with low cost', HTTP API wins. When the question involves complex API management features or partners, REST API is usually correct.
Quick Check
Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.
Lesson Recap
In this lesson you learned: REST API provides the full API Gateway feature set (caching, transforms, usage plans, WAF) at a higher cost, HTTP API is 70% cheaper with built-in JWT auth and lower latency, ideal for Lambda/HTTP proxy scenarios without advanced features, and WebSocket API enables server-push real-time communication over persistent connections for chat, gaming, and live data applications. Next up we explore API Gateway integrations with Lambda, HTTP backends, and mock responses.
Frequently asked questions
Is the “REST API vs HTTP API vs WebSocket API” lesson free?
Yes — the full text of “REST API vs HTTP API vs WebSocket API” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.
What will I learn in “REST API vs HTTP API vs WebSocket API”?
Understand the tradeoffs between REST API (feature-rich), HTTP API (low-latency, low-cost), and WebSocket API (bidirectional) and choose appropriately. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Solutions Architect?
No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “REST API vs HTTP API vs WebSocket API” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Solutions Architect lesson?
Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- REST API vs HTTP API vs WebSocket API
- Integrations: Lambda, HTTP, and Mock
- Authorization: IAM, Lambda Authorizers, and Cognito
- Throttling, Caching, and Usage Plans