Lesson 2: REST Clients, GET Requests, Node Architecture

  Overview

Introduction

Welcome to lesson two! This lesson, you will learn how to better organize your Node.js code to create web services more efficiently. You will also learn how to use REST clients to effectively test your services when there isn't a frontend available to consume them. Lastly, you will create a number of HTTP GET requests that will push you to learn more about how HTTP requests work in general.

Topics for this lesson:

  • Connect API to MongoDB Securely
  • Rest Clients
  • GET Requests
  • Query Parameters
  • Debugging Node.js Applications
  • Headers
  • Node Architecture and API Organization
Have Feedback?

  Learning Material

Resources for this lesson are accessible to you in this repository

The following learning material may be helpful but is not required. Please reference the syllabus for more details.

REMEMBER: You will never push sensitive information to GitHub. Your MongoDB connection string should be stored in an .env file. This .env file should be listed in your .gitignore file so that it never gets included in your commits.

A REST client is a tool that allows us to invoke a REST service API. In lesson 1, we created our first GET request API and we actually ended up seeing that data directly in the browser. To an extent, our browser functioned as our REST client last week. However, there are many things that our browsers cannot do without some client-side code. For example, if I needed to make a GET request with any type of dynamic data, headers, authentication keys, or other similar pieces of data, I would not be able to unless I had a frontend project in place. REST clients on the other hand, will allow us to make all sorts of HTTP requests with all sorts of data in an environment that is intuitive and convenient.

The number of REST clients in production today is very great, with these programs coming and going like much of the software we see on a regular basis. Here are several REST clients being used widely in industry today:

You can read about many others in this Google search.

There are a lot of different ways to learn about GET requests, and you're likely already familiar with what they are from previous classes you've taken. For example, in WDD 230, you made several fetch requests (JavaScript client way of sending http requests to a server), to get temple data, or weather data...those were GET requests. Here are some resources below to learn more about these, and also to learn how to make them in Node.

  Team Assignment

Overview

Purpose: Develop an API for an existing frontend.
Task: Complete the assignment.

To complete this assignment, you will create a backend for a frontend that is already complete. After building your API endpoints, you will be able to use the frontend to both test it and to see your data in action.


  Personal Assignment

Overview

Purpose: Connect API to a database.
Task: Complete the assignment.

Learning Objectives

By the end of this assignment the student will be able to do the following:

Assignment Description

For this lesson's personal assignment, you will add to your assignment from the previous lesson where you created a web server and a single GET request. In this assignment, you will create a collection in MongoDB, and then create a GET request that will return data from it. You will also practice using tools that you have been learning over the last few days. Below are the steps to complete this task:

Rubric

CriteriaWeightMasteryProficientDevelopingBeginningMissing/Incomplete
100%90%78%65%0%
API Endpoints

(Graded via Render)
30%Meets Proficient criteria plus application has a GET request that retrieves a single contact from their IDMeets Developing criteria plus application has a GET request that returns all the contacts in your collectionMeets Beginning criteria plus application Render url is accessible without errorsNode project runs without errorsRender link not submitted
MongoDB Connection

(Graded via YouTube)
30%Meets Proficient criteria and sensitive database information is stored securely in .env file and Render Config Vars (not pushed to GitHub)Meets Developing criteria and application successfully reads data from MongoDBMeets Beginning criteria and application successfully connects to MongoDBMongoDB attempt shown in videoYouTube link not submitted or no evidence of MongoDB
Security

(Graded via YouTube)
20%Meets Proficient criteria plus video shows that Config Vars are used in RenderMeets Developing criteria plus .env file is local project shown in video (no need to open the file)Meets Beginning criteria plus no MongoDB credentials are stored in GitHub (.env file is NOT in GitHub)Application connects to MongoDBYouTube link or GitHub link not submitted or no MongoDB implementation
Architecture

(Graded via GitHub)
20%Meets Proficient criteria plus includes a .rest file with routes for localhost and RenderMeets Developing criteria plus each route calls a function imported from a controllerMeets Beginning criteria plus server connects to routes in project "routes" folder using only a single line of codeServer file is present in root folder (server.js, index.js or app.js) to run the Node projectRender link not submitted