Creating a Shop API of POST cart items with Postman, lambda and API Gateway using AWS

2022.01.31

API

It stands for Application Program interface which helps in connection of two applications, computers, or between computer programs to talk to each other. It is used to access data, server software, or other applications and has been around for some time. Each time anyone uses a particular app for weather updates or good restaurants in an app API is used.

API Gateway

A fully managed service that makes developers easily create, publish, maintain, monitor, and secure APIs at any scale. API Gateway can be used to create Restful APIs and WebSocket APIs which have real-time two-way communication applications. It is a front door for applications to access data, business logic, or functionality from your backend services.

AWS Lambda

A serverless compute service which runs code as a reply to events and automatically takes care of the bottom resources. It runs code on high availability compute infrastructure and performs all the administration of the compute resources. A few examples are HTTP requests via Amazon API Gateway, changes to objects in S3, and many others.

Postman

It is an API client that makes developers create, share, test, and document APIs. It allows users to create and save simple and complex HTTP/s requests along with the read responses. It can make various types of HTTP requests such as GET, POST, PUT, PATCH it can also save environments that can be used later, it can also be used to convert the API to code for various languages such as JavaScript, Python, and many more.

Demo

Search for API Gateway in the AWS Console and click build on HTTP API Give an API Name and click next No changes right now in the configure routes and click next Give a name to the stage and keep the auto-deploy as the default Review and click on create Adding a path to routes and click create Choosing the POST method, entering the path and click create Go to lambda and click on create function Click on author from scratch, give a function name, keep other things as default and click on create function Making changes in code source and click deploy Going back to Routes of API Gateway click on POST and click on attach integration In the integration target choose “lambda function”, integration target “createcart” and click create Copy the invoke URL of API Paste the invoke URL in Postman of POST request with “/cart” Click body, json and add the below code and click send Scroll Down to see the response Going back to lambda -> Monitor -> views logs in Cloudwatch Clicking the log stream Data entered in the Postman can be seen here