YOUR NAME: - Temple MIS



YOUR NAME:MIS3502 – Assignment 05 – Rock Paper Scissors (API endpoint)In this assignment you will construct the API endpoint for a Rock-Paper-Scissors game. This endpoint is simplified in that it does not use a database connection. (That’s next week!)Put your answers in the boxes provided. Deliver the word document to your instructor as directed. Getting StartedTake a look at the original “Rock Paper Scissors” API endpoint that you used previously. We will be emulating much of this functionality.Open VS code and connect to your AWS server. WARNING: If you ignore step 2 and ty to do all this work locally on your own desktop / laptop you will be making more work for yourself! You would need to copy your work to your EC2 server, and you are on your own in figuring out how to do that. Working on your AWS server, use the following wget command to download the assignment05_endpoint.zip file. wget app.js in Visual Studio Code. Look it over. Get a “big picture” impression of what is included in this start file. Try running app.js in node. Make corrections. This means using npm to install any missing packages and specifying a port of 8201.Once you have the confirmation message “The server is listening on port: 8201” press control-c to quit the application. Immediately relaunch the app.js code with the Node monitor command:nodemon app.jsIf you get the error “nodemon: command not found” then you will need to npm install nodemon. The reason for doing this is to have a development environment were app.js is constantly being relaunched as you are working on it and saving changes. It’s a time saver.Writing the API endpointA wise person once said, “Begin with the end in mind”. Let’s start by adding some documentation. Look for the app event handler for the root event (“/”). Sample code follows://app event handlers go hereapp.get('/', function(req, res) { //what to do if request has no route ... show instructions let message = []; message[0] = "Instructions go here."; message[1] = "More instructions go here."; terminalWrite(res,message,200);});Replace message[0] and message[1] text with:“Issue a GET against ./shoot with a 'choice' token to get an array response. The array response has an element [0] that describes the outcome (win,loss,tie), and an element [1] that contains a number (0=loss,0.5=tie,1=win). Valid options for the choice token are: 'rock','paper','scissors'.”“Issue a GET against ./history with a 'usertoken' token to get a text response. The text summarizes history of the user's wins and losses against the computer.” Next we will write a supporting function (quick! Where should that go?) and call it pickHand. The function pickHand should use a Math.random() to generate a random number between 0 and 300. let r = Math.random() * 300;Use conditional statements to return one of the three strings (“rock”, “paper” or “scissors”) depending on the value of the variable r. Quick! How can we test this function we just wrote?We need another supporting function. This one will be called compareHands. It will take two parameters of type string: userChoice and computerChoice. The variables userChoice and computerChoice can have the values of “rock”, “paper” or “scissors”.Compare the two variables. The compareHands function should return an array. The first element of the array contains a piece of text such as:"Tie game. Go again!""You win! Paper covers rock.""You win! Rock breaks scissors.""You win! Scissors cut paper.""You lose. Paper covers rock.""You lose. Rock breaks scissors.""You lose. Scissors cut paper.""Error. No choice provided."The second element of the array will contain a 0, 0.5, 1.0 or -1 depending on the outcome of the comparison. (0 = “You lose”, 0.5 = “Tie game”, 1 = “You win” and -1 = “Error”) Quick! How can we test this function we just wrote?Now that you have all your supporting functions, you can use the app.get() method to manage a GET request and response. You can use the following code://what the app should do when it received a "get" against /shootapp.get('/shoot',function(req,res){ var result = ""; //get query string values var choice = req.query.choice; var computerchoice = pickHand(); result = compareHands(choice,computerchoice); terminalWrite(res,result,200);});Test your work.On your ownNotice that the text returned by our API does not quite match that returned by the misdemo server. For an example see: Improve your API so that the extra text (as in “You chose” and “Computer chose”) is generated by your API. Break tags are important too. Errors are important too. Test your work again. Make sure that wins, losses, and ties are correctly represented. Now add a new Express app.get call to listen for a “get” applied against “/history”. We will complete this code next week, so for now it is enough for this request to result in this message being returned to the browser: “This feature is under construction.”Use the Node package pm2 to set up your solution as a service running on your EC2 server. The service should continue to run – even after you are logged out / disconnected from the server. Test this! The URLs you provide in the next question need to be working as expected.(You may need to do a Google search or look at a past assignment for how to use pm2)Fill in the following boxes with URLs that point to your work on your own personal AWS server:Instructions (/)Shoot Event (/shoot) with a choice of “paper”Under Construction - History Request (/history) Get ready for next weekReview the Node.js and Express.js cheat sheet. Get familiar with the app.get() method.CONTINUED…Review the SQL commands found in the LinkedInLearning video “Learning SQL Programming” with Scott Simpson.For the quiz you should be comfortable with the following SQL commands:INSERTUPDATESELECT (against a single table)DELETESELECT (with aggregate functions - )Watch your inbox! Your instructor will be sharing a video with you. The video will cover your database setup instructions for the semester. HOT TIP! There are remarks in this assigned video that will be helpful on the next quiz. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download