
Source Code: https://git.io/fjBsN
In order to learn serverless computing on AWS, we will need a sample project. So, let’s take the canonical example used everywhere, that of a books catalog.
So, we are on a mission to develop API for managing book catalog. This basically means, we should be able to do CRUD operations on the catalog.
As we saw in earlier blog post, it is way easier to manage and deploy such projects using Claudia.js framework. So, we will be making use of it here.
1. PROJECT SETUP
Login to your Cloud9 IDE and create the folder structure like one below

Open Terminal windows on this folder by right-click and selecting Open Terminal here

Now we will install Claudia.js framework. Execute following command
npm init
Just enter description as shown below and leave rest of the fields blank by pressing ENTER
package name: book-catalog-api
description: Api for managing books catalog

Now we will install Claudia.js related packages. Enter following command
npm install -g claudia
Then execute another command
npm install claudia-api-builder -s
You should see confirmation of both installations as shown below

Now we have basic setup for the project. Let’s write some code.
Create a file called “index.js” under book-catalog-api folder and paste contents into it from GitHub
2. CODE FOR LAMBDA FUNCTIONS

Similarly, copy 5 files from GitHub in handlers folder also, as shown below

If you go through the code in above files, you will find that it has dummy functions which return static data. Let’s start with this right now and we will change the code to be more dynamic later.
3. DEPLOYMENT
Now let’s get started with deployment of this project. Execute the following command on your terminal windows


Presto! We have the deployment done
You can check that Claudia.js framework has created a Role as well as APIs for us.



So Claudia.js framework created the following things for us
- Role
- APIs
- Lambda function to service API
Also, we have created the following API endpoints
Sr. No. | Path | HTTP Method | Description |
1 | / | GET | API welcome page |
2 | /books | GET | Get all books |
3 | /books/{id} | GET | Get one book |
4 | /bookadd | POST | Add a book |
5 | /bookdelete/{id} | DELETE | Delete a book |
6 | /bookupdate/{id} | PUT | Update a book’s details |
Now we will test each endpoint
4. TESTING
Open Postman API testing utility and let’s hit all the endpoints one by one
Test-1: Test Root Url for API to get welcome message.
Url: https://f379vaq9uj.execute-api.us-east-1.amazonaws.com/latest
Result:

Test-2: Get all books
Url: https://f379vaq9uj.execute-api.us-east-1.amazonaws.com/latest/books
Method: GET
Result:

Test-3: Get one book
Url: https://f379vaq9uj.execute-api.us-east-1.amazonaws.com/latest/books/1
Method: GET
Result:

Test-4: Add a new book
Url: https://f379vaq9uj.execute-api.us-east-1.amazonaws.com/latest/bookadd
Method: POST
Payload

Result:

Test-5: Update a book (Let’s discount the price)
Url: https://f379vaq9uj.execute-api.us-east-1.amazonaws.com/latest/bookupdate/7
Method: PUT
Payload

Result:

Test-6: Delete a book
Url: https://f379vaq9uj.execute-api.us-east-1.amazonaws.com/latest/bookdelete/7
Method: DELETE

Let’s clean up the resources now by running the below command
claudia destroy
5. CONCLUSION
With this, we have taken first step in developing serverless API for a sample project. In next posts, we will keep refining it to add more features to it.
Happy Clouding!
[…] will now deploy this api project using the easy deployment method we have seen till now,i.e. using Claudia.js […]
LikeLiked by 1 person