CpS 404 Internet App Development

Exercise 2: Web Service

Your Submission Repo

Overview

In this assignment, you will create a Node.js web service using the Express framework, and deploy it to a public VPS that you set up in Lab 2. Successful VPS deployment is required in order for your assignment to be graded. See Lab 3 for the necessary procedures.

Your web service will allow contestants to register for a high school programming contest. Contestants must provide their first and last name, grade level, email address, t-shirt size, and a hackerrank username. The web service will store and retrieve registrations in a MySQL database. Create a registrations table in your database with columns with appropriate data types for each of the fields described below.

It must provide the following API:

  • Create a new registration:
    POST /registrations

    The body of the request should contain url-encoded values with the following field names: firstName, lastName, grade, email, shirtSize, hrUsername.

    The web service should perform basic validation as follows:

    • all fields must be nonblank
    • shirtSize must be S, M, or L
    • grade should be 9, 10, 11, or 12

    If validation passes, the web service should insert a new record in the registrations table and return status code 200. If validation fails, the web service should return status code 400, and a validation error message in the body of the response. If there is some database error, return status 500 and indicate the problem in the response body.

    A successful registration test with Curl (substitute the IP address of your server for 1.2.3.4 below):

    curl -X POST -d 'firstName=Abe&lastName=Jones&grade=10&email=abejones@gmail.com&shirtSize=S&hrUsername=ajones' http://1.2.3.4/registrations
    
  • List registrations:
    GET /registrations

    The body of the response should contain a JSON representation of all of the registration records.

Instructions

  1. Follow the instructions in Lab 3 to setup a VPS, install the necessary software, learn how to deploy a Node.js app.

  2. Use the lab3 folder as the starting point for this exercise. Copy your lab3 folder and rename to exercise2. Modify the Node.js express application to implement the web service described above. Configure it to run when the server starts, using the techniques demonstrated in the lab.

Tips

  • You can develop and test the application on your own computer before deploying it to your VPS instance. You can either install your own MySQL server on your workstation to facilitate this, or use the dockerized version on your AWS instance.

Submission

  1. Clone your submission repo using the link at the top of this page. Copy your project files into it (the contents of your exercise2 folder should be at the top level of your submission repo) and use git to submit. Include the following files at the top level of the submission folder (they should not be in a folder):

  2. A TESTING.md document containing curl commands that can be used to test your deployed application. The commands should test both success scenarios and error scenarios. Each command should have a brief explanation indicating what it tests. Use appropriate Markdown formatting.

  3. Create a report following these instructions. In the Test Results section include transcripts showing tests of your application using the curl commands in your README file.