How to create RestAPI Using AWS API Gateway service
The Amazon API Gateway is an AWS application built to build, upload, manage, track and protect REST, HTTP, and WebSocket APIs on any size. As well as data stored in the AWS Cloud, Application developers can build Applications that control AWS or other cloud resources. As a developer of API Gateway APIs, you can build APIs for use of your own client applications. Or you can make the APIs visible to the device of the developers from third parties.
API Gateway REST API
A collection of HTTP tools and methods combined with HTTP endpoints, Lambda functions, or other AWS utilities for the backend. That selection can be implemented in one or more phases. Usually API services are arranged according to domain logic in a resource tree. Each API tool can expose one or more API methods which are provided by API Gateway with specific HTTP verbs.
API Gateway HTTP API
A list of routes and methods combined with HTTP endpoints or Lambda functions on the backend. That selection can be implemented in one or more phases. That route can expose one or more API methods which are provided by API Gateway with specific HTTP verbs.
API Gateway WebSocket API
A list of WebSocket routes and path keys combined with HTTP endpoints, Lambda functions or other AWS features for the backend. That selection can be implemented in one or more phases. API methods are invoked by WebSocket frontend connections which you can link with a specific domain name associated with.
this was the brief introduction of what is API Gateway, so now we are going to learn how to create API Gateway and integrate it with a lambda function. so let's get started!!!!!
Step 1: As in the previous blog we already learned how to login to the AWS console, after this go the services option on the top and then select your API Gateway option from the Networking & Content Delivery.
Step 2: After clicking on the service your API Gateway Dashboard will be open after that click on the Create API button as marked in the below image.
Step 3: Choose the REST API option as shown in the below image.
Step 4: Choose the options as marked below and then give the name of your API and if you want to give some description and the select your Endpoint type, then click on the Create API button as marked with the arrow in the below image.
Step 5: click on the action button and then click on the create resource option, to create the new resource for your API.
Step 6: give your resource name and resource path as you want and then click on the create resource button below.
Step 7: after your resource will be created you can see your resource like this and then we have to create a method for this so click again on the action button, and then click on create method option.
Step 8: Select the method which you want for your API here we are creating Post Method for our API and then click on the check option.
Step 9: your method is created now you have to choose with which service you want to integrate your API, here we are choosing lambda function to choose your lambda region and choose any lambda function you have already created and click on save button.
Note: In the previous blog we have already explained to you how to create a lambda function that lambda function we are using here, you can create another lambda function and integrate here.
Step 10: Now you can see the details of your lambda integration, if you want to go back then click on the method execution option is marked in the below image.
Step 11: now you can see so many options here like Method request, Integration request, Method response, Integration response. so let us get some brief introduction of what it is:
In API Gateway, the public interface of an API system that determines the parameters and structure that an web developer needs to send in requests to reach the backend via the API.
A REST API ‘s public interface which specifies the status codes, headers, and body models that an app developer can expect from the API responses.
The internal configuration of a WebSocket API route or REST API method in API Gateway, where you map the body of a request for a path or the parameters and body of a request for a method to the formats needed by the backend.
The internal interface in the API Gateway of a WebSocket API route or REST API process, where you map the status codes, headers, and payload obtained from the backend to the address format returned to a client device.
To test your API before Deploying click on the test button as marked in the below image.
Step 12: Leave everything as it is and click on the test button.
Step 13: You can see the response you have set that you got and the response from lambda function also came as marked in the below image. it means your API is successfully integrated with the Lambda function.
Step 14: Now you have to deploy your API so click on the action button again and click on the Deploy API option as marked below.
Step 15: Select your Deployment stage and give your stage name and description if you want to add and click on the deploy button as shown in the below image.
Step 16: So now you got your Invoke URL of your API and consume your API with your website or where ever you want and enjoy it.
Now we have other options like Authorizer stages etc which you can explore by doing more practice.
Hope this information is helpful for you.