• Latest
Building a Rest API With AWS Gateway and Node.js

Building a Rest API With AWS Gateway and Node.js

March 8, 2023
6IX9INE CAUGHT LACKING GETS BEAT UP. TAXSTONE FOUND GUILTY. NEW YORK GANGS GOING CRAZY & MORE

6IX9INE CAUGHT LACKING GETS BEAT UP. TAXSTONE FOUND GUILTY. NEW YORK GANGS GOING CRAZY & MORE

March 25, 2023
INSANE Dual Screen Laptop! – ASUS Zenbook Pro Duo First Look

INSANE Dual Screen Laptop! – ASUS Zenbook Pro Duo First Look

March 25, 2023
Marques Brownlee Digital Drawing  ( Kinda Fool Vexel Photoshop Cc 2019 )  Speedart

Marques Brownlee Digital Drawing ( Kinda Fool Vexel Photoshop Cc 2019 ) Speedart

March 25, 2023
FORTNITE & Marques Brownlee

FORTNITE & Marques Brownlee

March 25, 2023
What Are You Playing This Weekend? (March 25th)

What Are You Playing This Weekend? (March 25th)

March 25, 2023

Dead Island 2’s gory opening cinematic revealed

March 25, 2023
VypDrive Ep 22: Marques Brownlee On Deck

VypDrive Ep 22: Marques Brownlee On Deck

March 25, 2023
nubia Pad 3D is now available for pre-order

nubia Pad 3D is now available for pre-order

March 25, 2023
Poll: Will you be playing the Diablo IV open beta this weekend?

Poll: Will you be playing the Diablo IV open beta this weekend?

March 25, 2023
FAT JOE SHUTDOWN HASSAN CAMPBELL’S PAGE? 🤯 #ShowfaceNews

FAT JOE SHUTDOWN HASSAN CAMPBELL’S PAGE? 🤯 #ShowfaceNews

March 25, 2023
EXTREME LOUD NECK CRACK 😱🔥| CERVICAL PAIN RELIEF | NECK PAIN #shorts #neckcrack  #neckadjustment

EXTREME LOUD NECK CRACK 😱🔥| CERVICAL PAIN RELIEF | NECK PAIN #shorts #neckcrack #neckadjustment

March 25, 2023
Disney Speedstorm Reveals New Competitive Mode “Regulated Multiplayer”

Disney Speedstorm Reveals New Competitive Mode “Regulated Multiplayer”

March 25, 2023
Advertise with us
Saturday, March 25, 2023
Bookmarks
  • Login
  • Register
GetUpdated
  • Game Updates
  • Mobile Gaming
  • Playstation News
  • Xbox News
  • Switch News
  • MMORPG
  • Game News
  • IGN
  • Retro Gaming
  • Tech News
  • Apple Updates
  • Jailbreak News
  • Mobile News
  • Software Development
  • Photography
  • Contact
No Result
View All Result
GetUpdated
No Result
View All Result
GetUpdated
No Result
View All Result
ADVERTISEMENT

Building a Rest API With AWS Gateway and Node.js

March 8, 2023
in Software Development
Reading Time:8 mins read
0 0
0
Share on FacebookShare on WhatsAppShare on Twitter


AWS Gateway is a powerful tool for building APIs that scale to meet the demands of modern web and mobile applications. With AWS Gateway, you can create RESTful APIs that expose your data and business logic to developers, who can then build rich, interactive applications that consume your API.

REST API is an industry standard for building scalable, distributed web applications. With AWS Gateway, you can easily build a REST API that supports both GET and POST methods, as well as complex query parameters. You can also add support for other HTTP methods, such as PUT, DELETE, and HEAD.

Using AWS Gateway, you can quickly create APIs that are secure and robust. You can also use it to deploy your code to a production environment with minimal effort. Additionally, AWS Gateway allows for seamless integration with other AWS services, such as S3 and DynamoDB, enabling you to easily add complex functionality to your APIs.

Prerequisites

Before building a RESTful API with AWS Gateway, you should have the following in place:

  • Create an AWS account if you don’t have one already.
  • Log in to the AWS Management Console and navigate to the Amazon API Gateway service.
  • Amazon API Gateway service

    Click on “Create API” and select “REST API.”

REST API

Choose the protocol

  • Click on “Actions,” and define the resource and click “Create Resource.”
New Child Resource
  • Select the newly created resource and click on “Create Method.”

Create Method

GET Setup

  • Choose the HTTP verb (e.g., GET, POST, PUT, etc.) and click on the checkmark to create the method.
  • In the “Integration type” section, select “Lambda Function” and enter the name of the Lambda function you want to use to handle the API requests. Click on “Save” to create the API.
AWS Lambda function
  • Select Node from the Runtime Dropdown.
    Select Node

Code Example

let user = {
    firstName: "John",
    lastName: "Smith",
    location: "Bay Area"
}
export const handler = async(event) => {
    // TODO implement
    console.log(">>>> Inside Lambda Function....");
    if(event.httpMethod === "GET")
    {
        getUserRecord(event);
    }
    if(event.httpMethod === "POST")
    {
        createUserRecord(event)
    }
    const response = {
        statusCode: 200,
        body: JSON.stringify({
            user_details: user
        })
    };
    return response;
};
function getUserRecord (event) {
    const response = {
        statuscode: 200,
        body: JSON.stringify({
            user_details: user
        })
    };
    return response;
}
function createUserRecord(event) {
    const body = JSON.parse(event.body);
    const response = {
        statusCode: 200,
        body:JSON.stringify({
            message: "successfully created",
            details: body
        })
    };
    return response;
}

The code first creates an object called user that contains some properties like firstName, lastName, and location.

Then the handler function checks the HTTPMethod property of the event object; if it’s “GET,” it calls the getUserRecord function, and if it’s “POST,” it calls the createUserRecord function.

Both getUserRecord and createUserRecord functions take the event object as input and return the response object.

In the getUserRecord function, it creates a response object with a statusCode of 200 and a body that contains a JSON object with user_details property which is the user object created at the beginning.

In the createUserRecord function, it first parse the event.body which is a string, into a JSON object and then creates a response object with a statusCode of 200 and a body that contains a JSON object with message and details properties.

Deploy the API by clicking on “Actions” and selecting “Deploy API.”

Deploy API

Select a deployment stage (e.g., “prod” or “test”) and click on “Deploy.” Use the generated API endpoint to make requests to your API.

Running and Testing The Code in Postman

Now, our API is up and running. You can send a test HTTP request through Postman. By sending a request to your invoke URL, you should see a 200 OK status code. For this test, no request body is needed for the incoming request.

Request

Wrapping Up

With that, we’ve created a simple RESTful API using AWS Lambda. This code can then be expanded on as needed to build APIs for your applications.



Source link

ShareSendTweet
Previous Post

Get started with flash photography: Understanding the basics

Next Post

Metroid Fusion Hits Nintendo Switch Online Next Week

Related Posts

Top 5 Data Streaming Trends for 2023

March 25, 2023
0
0
Top 5 Data Streaming Trends for 2023
Software Development

Data streaming is one of the most relevant buzzwords in tech to build scalable real-time applications in the cloud and...

Read more

10 Things to Know When Using SHACL With GraphDB

March 25, 2023
0
0
10 Things to Know When Using SHACL With GraphDB
Software Development

Today I have one of those moments where I am absolutely sure if I do not write this down, I...

Read more
Next Post
Metroid Fusion Hits Nintendo Switch Online Next Week

Metroid Fusion Hits Nintendo Switch Online Next Week

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

© 2021 GetUpdated – MW.

  • About
  • Advertise
  • Privacy & Policy
  • Terms & Conditions
  • Contact

No Result
View All Result
  • Game Updates
  • Mobile Gaming
  • Playstation News
  • Xbox News
  • Switch News
  • MMORPG
  • Game News
  • IGN
  • Retro Gaming
  • Tech News
  • Apple Updates
  • Jailbreak News
  • Mobile News
  • Software Development
  • Photography
  • Contact

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?