LibraryAPI Gateway Concepts: Resources, Methods, Integrations

API Gateway Concepts: Resources, Methods, Integrations

Learn about API Gateway Concepts: Resources, Methods, Integrations as part of Serverless Architecture with AWS Lambda

Understanding API Gateway Concepts for Serverless APIs

API Gateway acts as the front door for applications to access data, business logic, or functionality from your backend services. For serverless architectures, particularly with AWS Lambda, it plays a crucial role in managing, securing, and scaling your APIs. This module breaks down the core concepts: Resources, Methods, and Integrations.

API Gateway Resources: The Building Blocks

In API Gateway, a 'Resource' represents a logical container for your API's operations. Think of it as a URL path segment. For example, in a RESTful API, '/users' or '/products/{productId}' would be considered resources. Resources are hierarchical, allowing you to structure your API endpoints logically.

Resources define the structure of your API endpoints.

Resources are like folders or paths in your API. For instance, '/users' is a resource, and '/users/{userId}' is a sub-resource representing a specific user.

API Gateway resources are hierarchical. A parent resource can have child resources. For example, '/orders' could be a parent resource, and '/orders/{orderId}' would be a child resource. This structure helps organize your API and map directly to your backend logic. Each resource can have one or more HTTP methods associated with it.

API Gateway Methods: The Actions

An HTTP 'Method' (also known as an operation or verb) defines the action that can be performed on a specific resource. Common HTTP methods include GET, POST, PUT, DELETE, and PATCH. Each method on a resource represents a distinct API operation.

HTTP MethodPurposeCommon Use Case
GETRetrieve dataFetching a list of users or details of a specific product.
POSTCreate new dataAdding a new user or submitting a new order.
PUTUpdate existing data (replace)Updating all details of a specific product.
DELETERemove dataDeleting a user account or an order.
PATCHPartially update dataUpdating only the email address of a user.

API Gateway Integrations: Connecting to Backends

An 'Integration' defines how API Gateway connects to your backend service to execute the requested operation. For serverless APIs with AWS Lambda, this typically means configuring API Gateway to invoke a Lambda function. API Gateway supports various integration types, including Lambda, HTTP, and Mock.

Integrations link API Gateway requests to backend logic.

An integration tells API Gateway where to send the request and how to handle the response. For Lambda, it's the bridge between an API call and your serverless function.

When a client makes a request to an API Gateway endpoint (e.g., GET /users), API Gateway looks at the configured integration for that resource and method. For a Lambda integration, it maps the incoming request parameters, headers, and body to the Lambda function's event payload. It then invokes the Lambda function. Once the Lambda function executes and returns a response, API Gateway maps that response back to the client. This mapping can involve transforming the data format or status codes.

Imagine your API Gateway as a smart receptionist. Resources are the different departments (e.g., 'Customers', 'Orders'). Methods are the specific actions you can request from a department (e.g., 'Get Customer List', 'Create New Order'). The integration is the internal phone line and process that connects the receptionist to the right person (your Lambda function) in that department to fulfill your request. The receptionist also handles formatting the request for the internal contact and presenting the response back to you.

📚

Text-based content

Library pages focus on text content

Putting It All Together: A Simple Example

Let's say you want to create an API endpoint to get a list of products.

  1. Resource: You'd create a resource named
    code
    /products
    .
  2. Method: On the
    code
    /products
    resource, you'd create a
    code
    GET
    method.
  3. Integration: You'd configure this
    code
    GET /products
    method to integrate with an AWS Lambda function (e.g.,
    code
    listProductsLambda
    ). This Lambda function would be responsible for querying your product database and returning the list of products.
What is the primary role of an API Gateway 'Resource'?

A resource represents a logical container for API operations, typically corresponding to a URL path segment.

What does an API Gateway 'Method' define?

A method defines the specific HTTP action (like GET, POST, PUT, DELETE) that can be performed on a resource.

What is the purpose of an 'Integration' in API Gateway?

An integration defines how API Gateway connects to and interacts with backend services, such as AWS Lambda functions, to fulfill API requests.

Learning Resources

Amazon API Gateway Developer Guide(documentation)

The official AWS documentation providing a comprehensive overview of API Gateway concepts, including resources, methods, and integrations.

AWS Lambda Developer Guide(documentation)

Learn how to build and deploy serverless applications with AWS Lambda, understanding its role in conjunction with API Gateway.

Building a Serverless API with API Gateway and Lambda(blog)

A practical blog post from AWS that walks through setting up a serverless API, illustrating the concepts of resources, methods, and Lambda integrations.

Understanding API Gateway Request and Response Transformations(documentation)

Details on how API Gateway can transform request and response payloads, a key aspect of integrations.

API Gateway Integration Types(documentation)

Explores the different types of backend services that API Gateway can integrate with, focusing on Lambda and HTTP integrations.

REST API Concepts in API Gateway(video)

A video tutorial explaining the fundamental concepts of REST APIs within Amazon API Gateway, including resources and methods.

Serverless Architectures on AWS(documentation)

An overview of serverless computing on AWS, highlighting the role of services like API Gateway and Lambda in building scalable applications.

HTTP Methods Explained(documentation)

A foundational resource explaining the standard HTTP methods (GET, POST, PUT, DELETE, etc.) and their semantics.

API Gateway Lambda Proxy Integration(documentation)

Specific guidance on configuring Lambda proxy integration, a common and powerful way to connect API Gateway with Lambda functions.

What is an API?(blog)

A beginner-friendly explanation of what APIs are, providing context for understanding API Gateway's role.