This RESTful API is fully written in JavaScript. It is built using AWS API Gateway and AWS Lambda, with a MongoDB backend server; enabling information to be stored persistently in an online database. A Mongoose layer was installed and added to the API to configure the database connection. For testing purposes, a Google Chrome Extension Talend API Tester and the API testing environment on AWS was used. Further demonstrations will be in this documentation!
There are essentially four actions the user can take: Create a post, Edit a post, View a post (either view all posts or view a specific one), and Delete a post.
- Create a post
case: 'POST'
First, let's create a post. To do so, we must fill out the required information, which in this case is the name of the author, the content of the post, and the user-spcified password of the post. These information need to be in the Request Body, in JSON format. So, for instance, if we wish to add a post Minjae created that says Hello World! with the password minjae123, the following needs to be sent to be sent as the Request Body:
{
"name": "Minjae",
"content": "Hello World!",
"password": "minjae123"
}
As simple as that!
- Edit a post
case: 'PUT'
To edit a post, we need a user-specified password for that post. We send this password as a Header along with the updated post information in the Request Body, similarly as we did to Create a post. Let's update the content body of our post to "Content updated":
Success! We can see the changes in our database as well:
- View a post (View all post or a Specific post)
case: 'GET'
When we wish to view all of the posts, then we can use the GET method to access them. The run results of the method is:
Now, if we wish to view a specific post, then we can add a forward slash (/) and a Post # to the MongoDB URL. Say we wish to view tagging information of Post #4. Then, we will get the following run results:
- Delete a post.
case: 'DELETE'
Now, let's delete the post we created. We currently have a total of 4 posts on our database. Deleting a post requires a password. Let's delete Post #4, which has the password "minjae123". Similar to editing posts, we will pass the password as a Header:
Successfully deleted post! Now see our database: total number of posts has decreased from 4 to 3: