Git Product home page Git Product logo

08-rest-http's Introduction

cf Lab 08: Vanilla REST API

Submission Instructions

  • fork this repository & create a new branch for your work
  • write all of your code in a directory named lab- + <your name> e.g. lab-susan
  • 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

Learning Objectives

  • students will learn to use promise constructs to manage asynchronous code
  • students will learn to create a vanilla RESTful API with in-memory persistence

Requirements

Configuration

  • .gitignore
  • .eslintrc
  • package.json
  • README.md

Feature Tasks

  • create the following directories to organize your code:
    • lib
    • model
    • test
  • create an HTTP server using the native NodeJS http module
  • create an object constructor that creates a simple resource with at least 3 properties
    • include an id property that is set to a unique id (hint: you'll need to use uuid)
    • include two additional properties of your choice (ex: name, content, etc.)
  • create a custom body parser module that uses promises to parse the JSON body of POST and PUT requests
  • create a custom url parser module that returns a promise and uses the NodeJS url and querystring modules to parse the request url
  • create a router constructor that handles requests to GET, POST, PUT, and DELETE requests
  • create a storage module that will store resources by their schema type (ex: note) and id

Server Endpoints

/api/v1/simple-resource-name

  • POST request
    • pass data as stringified JSON in the body of a POST request to create a new resource
    • this should return a 201 status code with the new record content
  • GET request
    • pass ?id=<uuid> as a query string parameter to retrieve a specific resource (as JSON)
    • this should return a 200 status code with the requested record
  • PUT request
    • pass ?id=<uuid> as a query string parameter, with a body of data to update a specific resource (as JSON)
    • this should return a 204 status code with no content in the body
  • DELETE request
    • pass ?id=<uuid> in the query string to DELETE a specific resource
    • this should return a 204 status code with no content in the body

Tests

  • write tests to ensure the /api/v1/simple-resource-name endpoint responds as described for each condition below:
  • GET: test 400, it should respond with 'bad request' if no id was provided in the request
  • GET: test 200, it should contain a response body for a request made with a valid id
  • POST: test 400, it should respond with 'bad request' if no request body was provided or the body was invalid
  • POST: test 200, it should respond with the body content for a post request with a valid body
  • PUT: test 400, it should respond with 'bad request' if no request body was provided or the body was invalid
  • PUT: test 200, it should respond with the body content for a put request with a valid body
  • DELETE: test 400, it should respond with 'bad request' if no id was provided in the request
  • DELETE: test 200, it should contain a response body for a request made with a valid id

Stretch

  • A GET request to /api/simple-resource-name with no ?id= should return an array of all of the ids for that resource

08-rest-http's People

Contributors

sjschmidt44 avatar

Watchers

James Cloos avatar Joseph Waine 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.