Giter Club home page Giter Club logo

lab-09-10-11-express-api's Introduction

cf lab 09 single resource express api

Build Status

To Submit this Assignment

  • fork this repository
  • write all of your code in a directory named lab- + <your name> e.g. lab-duncan
  • push to your repository
  • submit a pull request to this repository
  • submit a link to your PR in canvas
  • write a question and observation on canvas

Build Tool Instructions

  • create a package.json that lists all dependencies and developer dependencies
  • include an .eslintrc
  • include a .gitignore
  • create a gulpfile
  • have a lint task for running eslint
  • have a test task for running mocha
  • have a nodemon task that restarts your server any time a change has been bade to your .js files
  • have a default task for running the lint and mocha tasks

Directions

  • Create these directories to organize your code:
  • lib
  • model
  • route
  • test
  • Create a HTTP Server using express
  • Create an Object Constructor that creates an AppError
  • create message, statusCode and responseMessage properties
  • add static methods to the Constructor that check if an error is an instanceof AppError
  • add statick methods for creating 400, 404, and 500 error messages
  • Use the AppErrors any where you find an error in your app.
  • If you encounter an error in your route respoond with the AppError status code, and response message
  • Create a Object Constructor that creates a simple resource with at least 3 properties
  • An id property that is set to a unique node-uuid id is required
  • Also include two other properties of your choice (like name, creationDate, etc.)
  • use the body-parser express middleware to on POST and PUT routes
  • use the npm debug module to log the functions being executed in your app
  • using the express Router create a route for doing RESTFUL CRUD operations on your simple resource
  • store all objects created on the in memory storage module we created in lecture

Server Endpoints

/api/simple-resource-name

  • POST request
  • pass data as stringifed json in the body of a post request to create a resource

/api/simple-resource-name/:id

  • GET request
  • pass the id of a resource though the url endpoint to req.params to fetch a simple-resource
  • PUT request
  • pass data as stringifed json in the body of a put request to update a resource
  • DELETE request
  • pass the id of a resource though the url endpoint to req.params to delete a simple-resource

Tests

  • your tests should start your server when they begin and stop your server when they finish
  • write a test to ensure that your api returns a status code of 404 for routes that have not been registered
  • write tests to ensure your /api/simple-resource-name endpoint responds as described for each condition below:
  • GET - test 404, responds with 'not found' for valid request made with an id that was not found
  • GET - test 400, responds with 'bad request' if no id was provided in the request
  • GET - test 200, response body like {<data>} for a request made with a valid id
  • PUT - test 400, responds with 'bad request' for if no body provided or invalid body
  • PUT - test 200, response body like {<data>} for a post request with a valid body
  • POST - test 400, responds with 'bad request' for if no body provided or invalid body
  • POST - test 200, response body like {<data>} for a post request with a valid body

Bonus

  • 2pts a GET request to /api/simple-resource-name/all should retrun an array of all of the ids for that resource
  • 1pt write tests for the DELETE request

lab-09-10-11-express-api's People

Contributors

slugbyte avatar

Watchers

James Cloos avatar yun joo kim 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.