Code Monkey home page Code Monkey logo

nodejs-assessment's Introduction

Node.js Assessment: Todo List API

For your unit 5 assessment you are required to create a RESTful API using Node.js and Express.js.

The API should create (POST), read (GET), update (PUT or PATCH) and delete (DELETE) from a list of todos. The todos.json file is used as the server's data store and can be found in the models folder.

Run through the Setup and Configuration steps to configure your API before you start developing.

Ensure your finished repository meets all of the Assessment Criteria listed below

Assessment Criteria

  1. Add the functionality for all the endpoints described below to your API:
Method URL Description Example URL Request Body Status Code Response Body
GET / Returns a static HTML file index.html containing a favicon.ico, logo.png and reference to an external stylesheet styles.css. http://localhost:8080/ 200 HTML page
GET /todos Return all todos from the todos.json file http://localhost:8080/todos 200 [{"id":"01507581-9d12-4c3a-bb60-19d539a11189","name":"Learn to use Adobe Photoshop","created":"2021-11-20T18:25:43.511Z","due":"2021-12-23T23:05:03.352Z","completed":false}, {...}, {...} ]
GET /todos/:id Return a specific todo with the corresponding id http://localhost:8080/todos/01507581-9d12-4c3a-bb60-19d539a11189 200 or 404 if id not found {"id":"01507581-9d12-4c3a-bb60-19d539a11189","name":"Learn to use Adobe Photoshop","created":"2021-11-20T18:25:43.511Z","due":"2021-12-23T23:05:03.352Z","completed":false}
GET /todos/overdue Return a list of overdue todos or an empty list if there are no overdue todos. Todos can be filtered based on their due date attribute http://localhost:8080/todos/overdue 200 [] or [{todo1},{todo2},{...}]
GET /todos/completed Return a list of completed todos or an empty list, if no todos have been completed. Todos can be filtered based on their due date attribute. http://localhost:8080/todos/completed 200 [] or [{todo1},{todo2},{...}]
POST* /todos Add a new todo to the todo list http://localhost:8080/todos {'name' : 'Buy oatmilk x 2', 'due':'2021-11-20T18:25:43.511Z'} 201 (Created), 400 (Bad Request) if incorrect data submitted
PATCH* /todos/:id Edit the name and/or due date attributes of a todo. http://localhost:8080/todos/:9d127581-0150-4c3a-bb60-1118919d539a {"name":"Buy 3 Cartons of Oat Milk","due":"2021-12-23T18:25:43.511Z"} 200 (OK) or 404 (Not Found) if invalid id or request attributes
POST* /todos/:id/complete Update todo, set attribute complete to true http://localhost:8080/todos/01507581-9d12-4c3a-bb60-19d539a11189/complete 200 (OK) or 404 (Not Found) if invalid id
POST* /todos/:id/undo Update todo, set attribute complete to false http://localhost:8080/todos/01507581-9d12-4c3a-bb60-19d539a11189/undo 200 (OK) or 404 (Not Found) if invalid id
DELETE* todos/:id Deletes a todo by id http://localhost:8080/todos/01507581-9d12-4c3a-bb60-19d539a11189 200 (OK) or 404 (Not Found) if invalid id

*POST, PUT, PATCH and DELETE methods may need an API testing tool such as Postman to test.

Expected Structure of a Todo

  {
    "id":"01507581-9d12-4c3a-bb60-19d539a11189",
    "name":"Learn to use Adobe Photoshop",
    "created":"2021-11-20T18:25:43.511Z",
    "due":"2021-12-23T23:05:03.352Z",
    "completed":false
  }

Setup and Configuration

  1. Clone this repository to your local machine. Once cloned, open in Visual Code.

  2. Create a file called .env in your home directory (outside of the src folder). Add the following text:

BASE_JSON_PATH="/models/todos.json"

This will ensure the current starter code is using the todos.json in the models folder.

In your code when saving the updated list of todos back to the todos.json file, use the following environment variable:

process.env.BASE_JSON_PATH

e.g.

fs.writeFile(__dirname + process.env.BASE_JSON_PATH,  content, err => {
    if (err) {
      console.error(err)
      return
    }
}
  1. Run the following commands to install any dependencies:
npm install
  1. In the index.js file you will find some initial code. Read through, understand and uncomment the code to implement a basic static server with two endpoints.

  2. Once you have completed the steps above. You can start the API with the following command:

npm start
  1. If configured correctly, when you visit the local URL: http://localhost:8080/, you will see the following page:

index.html screenshot

  1. To complete the assessment make additions to the index.js file to return the expected data. Review the assessment criteria for detailed information on expected endpoints for your completed API.

How to submit

Commit all files and folders to the repo and push to your remote repo for assessment.

nodejs-assessment's People

Contributors

efuaakum avatar tanyapowell avatar genyus avatar dependabot[bot] 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.