Amazon API Gateway supports multiple types of APIs, each designed to support different protocols and use cases. The main types are HTTP API, REST API, and WebSocket API.
Blog
Amazon API Gateway HTTP APIs are lightweight APIs designed for HTTP-based interactions and are ideal for simple, stateless, and high-performance applications.
Characteristics:
Usage Scenarios:
Example:To create a simple HTTP API in Amazon API Gateway, here’s what you might configure:
aws apigatewayv2 create-api \ --name MyHttpApi \ --protocol-type HTTP
In this example, when a client makes a GET
request to /hello
, API Gateway forwards the request to the Lambda function sayHelloLambda
, which processes the request and returns a response.
Amazon API Gateway REST APIs are fully-managed RESTful APIs that support HTTP/1.1 and are built to handle RESTful CRUD operations (Create, Read, Update, Delete). REST APIs on API Gateway provide comprehensive features like fine-grained control over authorization, throttling, monitoring, and caching.
Characteristics:
Usage Scenarios:
Example:Creating a REST API in Amazon API Gateway for managing a resource (e.g., items) might look like this:
aws apigateway create-rest-api \ --name MyRestApi \ --description "API for managing items"
In this example:
Amazon API Gateway WebSocket APIs are designed to support real-time, bidirectional communication between clients and servers. WebSocket APIs are ideal for applications that require instantaneous updates and persistent connections.
Characteristics:
Usage Scenarios:
Example:A WebSocket API setup for a simple chat application might look like this:
Route: $connect
(when a user connects), $disconnect
(when a user disconnects), sendMessage (to send a message).Integration: AWS Lambda function chatHandlerLambda
aws apigatewayv2 create-api \ --name MyWebSocketApi \ --protocol-type WEBSOCKET \ --route-selection-expression "$request.body.action"
In this example:
Use HTTP API when:
Use REST API when:
Use WebSocket API when:
1. Regional REST API - A Regional REST API is deployed in a specific AWS region and intended for use within that region or nearby regions. This type of API doesn’t use CloudFront for global distribution but provides flexibility in deploying CloudFront as needed.
Characteristics:
Use Cases:
2. Edge-Optimized REST API - An Edge-Optimized REST API is deployed globally using Amazon CloudFront as a content delivery network (CDN). This type of API is optimized for latency and performance by caching content at AWS edge locations closer to the user.
Characteristics:
Use Cases:
3. Private REST API - A Private REST API is accessible only from within your VPC (Virtual Private Cloud), making it ideal for internal or private APIs. Access is restricted to clients in the same VPC, allowing better control and security for sensitive data.
Characteristics:
Use Cases:
Copyright ©2024 Preplaced.in
Preplaced Education Private Limited
Ibblur Village, Bangalore - 560103
GSTIN- 29AAKCP9555E1ZV