Open In App

Build an API Gateway REST API with HTTP Integration

Improve
Improve
Like Article
Like
Save
Share
Report

Pre-requisite: AWS

We can use either the HTTP proxy integration or the HTTP custom integration to build an API using HTTP integration. When feasible, leverage HTTP proxy integration for faster API setup while delivering varied and strong functionality. If it is essential to change client request data for the backend or backend response data for the client, HTTP custom integration might be appealing.

HTTP proxy integration is a simple, powerful, and adaptable way of creating an API that allows a web application to access numerous resources or features of the integrated HTTP endpoint, such as the full website, using a single API call. API Gateway sends the client-submitted method request to the backend via HTTP proxy integration. Request headers, query string parameters, URL path variables, and payload are all part of the request data that is passed through. The backend HTTP endpoint, often known as the web server, parses the incoming request data to determine the answer. Except for known limitations such as unsupported characters, which are noted in Amazon API Gateway’s important notes, HTTP proxy integration allows the client and backend to connect directly with no interference from API Gateway when the API method is set up.

You can use an HTTP proxy integration to establish an API of a single API method using the all-encompassing proxy resource {proxy+} and the catch-all ANY verb for the HTTP method. The method exposes a website’s whole collection of publicly available HTTP resources and actions. When the backend web server makes more resources available to the public, the client can use them using the same API configuration.

The following lesson serves as an overview of HTTP proxy integration. In this tutorial, we will construct an API using the API Gateway interface to interact with the PetStore website using a generic proxy resource {proxy+} and the HTTP method placeholder ANY.

Steps To Build an API with HTTP Proxy Integration with the PetStore Website through a Proxy Resource

Step 1: Access the API Gateway console by going AWS console.

Step 2: Choose Build from the REST API menu. Choose OK when the Create Example API box displays.

Creating the REST API

 

Creating REST API

 

Step 3: Choose New API

Step 4: Enter a name in the API Name.

Step 5: Add a brief description in the Description field if desired.

Step 6: Click Create API.

Choosing the protocol for REST API

 

Step 7: Pick a parent resource item from the Resources tree and then choose to Create Resource from the Actions drop-down menu to create a child resource.

Creating the Resource for REST API

 

Step 8: To create a proxy resource, select the Configure as proxy resource option.

Step 9: Use the default name proxy in the Resource Name input text field.

Step 10: Use the default name /{proxy+} in the Resource Path input text field.

Step 11: Select Enable API Gateway CORS.

Step 12: Click Create Resource.

Creating the Child resource for existing resource

 

Step 13: Choose ANY from the HTTP method drop-down list, then click the check mark button to preserve your selection.

Step 14: Choose HTTP Proxy for Integration type.

Step 15: use http://petstore-demo-endpoint.execute-api.com/{proxy} for the Endpoint URL.

Step 16: Use default settings for other fields and click Save to finish configuring the ANY method.

Selecting the required HTTP setup

 

The API’s proxy resource path of {proxy+} becomes the placeholder of any of the backend endpoints under http://petstore-demo-endpoint.execute-api.com/ in the newly established API. For example, It can be a pet store, pet store/pets, or the pet store/pets/{petId}. At runtime, the ANY method acts as a placeholder for any of the available HTTP verbs.

Steps To Test an API with HTTP Proxy Integration

Step 1: In the Resources tree, choose ANY on a proxy resource.

Step 2: In the Method Execution window, select Test.

Selecting the method of execution

 

Step 3: Choose to GET from the Method drop-down list.

Step 4: In place of the proxy resource path ({proxy}), use pet store/pets for Path and type=fish for Query Strings.

Step 5: Leave other settings as it is.

Step 6: Click Test to test invoking the method.

Calling the method

 

Step 7: Because the backend website accepts the GET /pet store/pets?type=fish request, it returns the following successful response:

Checking the status code

 

Step 8: If you attempt to call GET /pet store, you will receive a 404 response with the error message Cannot GET /pet store. This is because the provided operation is not supported by the backend. Because the PetStore website supports GET /pet store/pets/1, you will receive a 200 OK response with the following payload.

Checking GET call was successful

 



Last Updated : 28 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads