Code Monkey home page Code Monkey logo

311_wk2_day1_express's Introduction

My First Web Server

A starter repo for the ACA 311 Express project.

Setup

Initialize and run the app: npm install && npm start.

Testing the routes

Use Postman to test the routes created in the following sections. Your base url will be localhost:4000 (whatever your port number is) and the paths will be the routes defined below. For example, if I wanted to test the users route I would plug in the following information to Postman:

Part 1: Basic routes

  • Create the following routes:

    • GET /users

      • Give your server the ability to respond to a GET request with a path "/users" and return the users array from state.js
      • Ex. res.json(users)
    • GET /users/1

      • Give your server the ability to respond to a GET request with a path "/users/1" and return the first user object from the users array from state.js
    • POST /users

      • Give your server the ability to respond to a POST request with a path "/users" and add a hard coded user object to the users array from state.js. Use res.json() to send the last user in the array (should be the new one) back to the client.
      • If you do another GET request you should see this added
      • You will need to create the hard coded user mentioned above
    • PUT /users/1

      • Give your server the ability to respond to a PUT request with a path "/users/1" and just change any key value (ex. name, occupation) on the first user object in the users array in state.js. Use res.json() to send this user back to the client.
    • DELETE /users/1

      • Give your server the ability to respond to a DELETE request with a path "/users/1" and remove the first item from the users array. Use res.send() to send back a messsage, "deleted"

Part 2. Body-parser module

  • Require the body-parser module on the line below require('express'). (it has already been npm installed)

  • Give your server the ability to handle a POST request with a path "/users" and add the data from the client to the users array

    • This means you will be adding req.body. Console log this to see what you get and don't forget to send an actual body with the request in Postman

    • Assign an _id property to the user object that is a number that increments by 1 each time.

      • To do this, set a variable called counter near the { users } variable. Start it at the length of the users array
    • Use res.json() to send the user object back to the client. (if you do another GET request you should see this added)

Part 3. Use path variables

  • Alter the following routes:

    • GET /users/1 => GET /users/:userId

      • Give your server the ability to respond to a GET request with a path /users/:userId and return the user object from the users array that has the _id == userId
    • PUT /users/1 => PUT /users/:userId

      • Give your server the ability to respond to a PUT request with a path /users/:userId and just change any key value on the user object with this _id
    • DELETE /users/1 => DELETE /users/:userId

      • Give your server the ability to respond to a DELETE request with a path /users/:userId and find the user with this id from the array. Give this user object a new key value isActive: false. Use res.send() to send back a messsage, "deleted"

311_wk2_day1_express's People

Contributors

mxviteri avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.