Serverless API with Claudia.js in 3 Steps

Claudia.js is a open source command line tool that makes rolling out serverless API’s on AWS easy. It uses your code as a blueprint to create an API layer on AWS API Gateway and prepares an AWS Lambda to handle the API requests. It then connects the API layer with the Lambda. The thing that makes this tool so great is that you don’t have to know the inner workings of AWS to start using it. Its so easy to use, you can get started with Claudia.js in just a few steps.

1) Install Claudia.js

If you don’t have Claudia.js installed on your machine, open up your terminal and run the following command to install it:

npm install -g claudia

That command will install Claudia.js globally so you can use it in any directory.

2) Create index file with API methods

In the root of your project directory create an index.js file and install claudia-api-builder.

npm install claudia-api-builder --save

Add the following Claudia.js template code :

var ApiBuilder = require('claudia-api-builder').
api = new ApiBuilder();
module.exports = api; 
api.get('/github', function (request) {
return request.queryString;
});

That code tells Claudia.js to create a [GET] API endpoint and tells Lambda to return its query string.

3) Deploy API

To deploy your API, open your terminal and execute the following command:

claudia create --region us-east-1 --api-module index

You should see some log information generated by that command. Claudia.js is creating and configuring AWS services and policies needed for the API to function. Once the deployment process is complete, take note of the URL in the JSON response that looks similar to the following:

https://szvp2y6a4c.execute-api.us-east-1.amazonaws.com/latest/github

Copy that URL and format it to include your API call and a query string and navigate to it in your browser window.

https://szvp2y6a4c.execute-api.us-east-1.amazonaws.com/latest/github?cat=meow

You should have received a response similar to this :

Have fun building API’s!