CSE 341: Web Services

W01 Project: Contacts Part 1

Overview

This project will store Contacts (such as friends or work colleagues). This is a two week project. As described below, you will need to complete the first part of the project in Week 01, then you will finish it in Week 02.

Project Description

This project will provide an API for storing and retrieving information about contacts. These contacts will be stored in a MongoDB database and all interaction will happen through the API that you create. You will not need to create a frontend for this project, instead you are creating the API that could be used by any frontend in the future.

Overall Requirements (Due at the end of Week 02)

The overall requirements for this project (to be completed in Week 02) are:

  1. Be sure to review the rubric in Canvas to see how you will be graded on this assignment.
  2. The database stores the following for each contact: firstName, lastName, email, favoriteColor, and birthday.
  3. Node project successfully connects to MongoDB.
  4. API routes perform GET, POST, PUT, and DELETE requests that are fully functional.
  5. API Documentation using Swagger is professional, comprehensive, relevant, and accurate.
  6. API is published to Render and can be called from external sources.
  7. Create a 5 to 8 minute video that goes through the items in Rubrics. Upload it to YouTube. Videos longer than the alloted time will receive a zero and will be asked to resubmit.
  8. Submit the following links in Canvas: GitHub repo, Render site, and YouTube video.

Contacts and Users

Please note that for this assignment, you will be creating collection of Contacts with the fields mentioned. To help you see how this is done, some tutorial videos are provided that create a collection of Users that have similarly, slightly different fields.

You should use the Users collection in the videos as a guide and a pattern, but for the assignment that you complete, make sure to use Contacts with the fields specified in the assignment instructions.

Part 1 requirements (Due at the end of Week 01)

To help you make progress toward finishing this project, for this week's assignment you need to complete the following:

  1. Set up the project and database.
  2. Import data into the database.
  3. Complete the GET API routes (get and get all).
  4. Deploy the app to Render.

Then, in Week 02 you will finish the app by adding in the POST, PUT, and DELETE endpoints as well as the API Documentation.

Use Course Tools

If you have not already, create a GitHub repository for your work. In this class, you will never submit code of any kind; you will always submit links to your work. You will always use the following tools:

If you use other tools to store, deploy or demo your code, you will not receive a grade.

Set up GitHub and Initialize Node Project

Begin your project by creating a new repository for it at GitHub and initializing a new Node.js project.

The following video may be helpful in completing this step:

Direct link: https://video.byui.edu/media/t/1_u8dzgu7e

Push to GitHub and Start with Express

Complete the following steps:

Direct Link: https://video.byui.edu/media/t/1_daxwlcz2

Install MongoDB and Import data

Complete the following steps:

Remember, the examples in the tutorial videos show a Users collection, but you should be creating a Contacts collection for this assignment. It is similar, but slightly different.

Direct Link: https://video.byui.edu/media/t/1_4dj3ierr

Connect your node project to MongoDB

Complete the following steps:

Direct Link: https://video.byui.edu/media/t/1_ujfu8vdx

Add the Get and GetAll endpoints

Complete the following steps:

Direct Link: https://video.byui.edu/media/t/1_0juwmhcn

Deploy and Test

Once these api routes are working, push to GitHub and test on Render to ensure everything works in that environment as well. (NOTE: The connection string stored in your .env file will not ever be pushed to GitHub, which means it won't be published to Render. You will need to add config vars to Render.)

Direct Link: https://video.byui.edu/media/t/1_r4st3h0l

Other Help with Deployment

Deploying Code to Render

Before attempting to deploy an API, you should first test your API thoroughly on your computer running on localhost. If you can successfully run it without errors, and test the API endpoints without errors, then you are ready to try a deploy to Render.

Render's Node.js Documentation for deployments is very simple and very good. It is recommended that you start here, but you'll use your own GitHub repository, and not their forked hello-world example.

Here are the steps for your first deploy:

Here is a video showing this

Environment variables and config vars Setup

To secure an application that needs to connect to a database, we will always use environment variables. Environment Variables are variables that are only stored in the environment to which a code base is running. So if I am running my local Node.js project on localhost, I would have a .env file in my project on my computer. However, I would never push this file to GitHub. Instead, I'll include the name of this file in my .gitignore file. Within it, I will put the MongoDB connection string that my application uses. This article has a great explanation of how to do this.

You may be wondering, "if I only have the db credentials stored on my computer, how will my API work on Render?" That is where config vars come in. Config vars are environment variables for the environment that your API will run in on Render's servers.

Render has excellent documentation on how to create config vars. And you will create the same ones that you did in your local .env file. This will allow your application to function in both environments, while never pushing database crendentials to a git provider like GitHub.

Here is a video showing how to do this

Testing your deployed API

Testing an API is incredibly simple if you have the right tool. The tool to test a RESTful API is called a REST client, and there are many free ones to choose from. One simple, straight-forward one that can be used is a VS code extension called REST Client.

As mentioned previously, if you've already tested your API locally, it will be the same process...just with your new url from Render.

Here is a video showing how to test the API

Prepare for Submission

Submission

When you have finished the assignment:

Other Links: