In this video we are going to develop lambda function for the incoming rest API, even json object to
perform business logic.
Let's get started.
For that purpose, open the Visual Studio code.
I have created a new folder specific folder for the lecture and I have added the our incoming event
object for the rest API to the lambda function.
We can see these images object and in the index file index file we have created the lambda function
and now we will develop our lambda function code.
So this is the basic implementation 100 method of lambda function.
This function designed for the API driven invocations to lambda function.
So this is starting with the logging incoming event.
After that we have tried cache block and in the tribe log we are returning to 100 success certificate
with the body information and in the case below we are logging the error and return vector 400 code
and the error message.
So this is designed for the API driven services equal to the base lambda for example, API gateway or
function from the lambda function.
Okay.
Now we are going to implement the actual business logic in here.
So in the actual logic, we will basically accommodate the incoming request from coming from the rest
API and we will accommodate these HTTP methods and implement the product related business logic into
the lambda function.
So as you remember that or even JSON objects are stored in here.
So basically if we examine these folders, the important attributes are resource, pet and static methods.
For example, this is the gate product and is the gate product by ID and this is the post product.
So the idea there is that we should write the switch block according to the HTTP method and after that
we will check the query string and pet parameters.
So let's get start to development.
Basically, I'm going to open the indexes and in here I have writing the switch statement in the K,
we should look at the event that HTTP method to verify this attribute.
You should get in here and copy from attribute name and come to code window and paste in here.
And if you look at the case, we should check the HTTP methods.
If you look at the exit method values in here in the method for the get request, it is get get the
ID.
It is again the same get post method.
The method is post.
So that means we should write the HTTP method case, get post and delete.
After that we will develop additional conditions for gate by ID looking for the setting parameters and
the parameters.
Okay, let's get started.
I'm going to copy these cases and after that I will explain one by one.
Here.
You can find the old case statement for our application.
So let me copy all and make it clear.
Yes.
Here you can point our switch statement.
Basically, we handle all incoming requests from the rest API by looking to our ATP method.
And after that, if the method is get, we have also additional condition, which is the looking query
setting parameters.
It took our setting parameters, including this event JSON object.
We are going to perform event parameters in here.
But if there is no query string, we are looking for the checking for the parameters and after that
apply the parameters.
For example, this is for get by ID.
If there is no parameters and setting parameters, that means we will return back to get all products
so you can check these HTTP methods.
Which condition is handled, which method?
You can see this, you can check the these command sections, for example, this one is handled get
product by ID and also create a setting parameter.
And after that we only check, get product ID and last condition is get all products.
So this is the first case for the gate condition, another case for the OR application looking for the
post.
You can see in here this is the post.
So in the post block I'm going to.
Check the event, buddy.
So we are basically passing the event the in order to get the payload.
After that, we are processing the payload for inserting a new item and so on.
So another case we look is the delete.
So in the delete method, http delete.
We basically check the parameters to delete which ID of the product.
So this is handled delete product by ID, this is handled post product.
So as you can see that we have implemented the switch block in accommodating the incoming events from
the rest API.
So now we should copy this line of codes and paste to our lambda function in order to deploy and see
how it is working in our application.
So let me make it more clean and copy all codes, remove blank characters and I am going to copy all
code.
You can also copy from this index file of the lecture folder and go to the our lambda function product
function go to functions, product function, open the code window and remove this code window copy
from here and paste in here.
So you can also check the codes and verify all with the codes in this place.
So after that you can click the deploy button.
Now we are ready for the test of our application.
So as you can see that we have developed our lambda function that can handle all request incoming from
the rest API.