Giter Site home page Giter Site logo

exercise-express's Introduction

Exercise: Express Produce Stand

This exercise will assess your ability to build upon an already existing Express API.

Setup

  1. Fork & Clone this repository
  2. npm install
  3. npm run dev

Instructions

Improve upon and/or build the following routes as specified.

GET /vegetables?name=[partial-query]

Note: This is not a new route!

  • e.g. GET http://localhost:5000/vegetables?name="pepper"

Return a list of all vegetables where the query is included somewhere in the name.

Correct Response Body Example

[
  { "id": "AEdvQm9t_", "name": "green pepper", "price": "0.99" },
  { "id": "JA_dIbXLW", "name": "red pepper", "price": "0.99" }
]

If there are no vegetables that match, just return an empty array.

Correct Response Body Example

[]

DELETE /vegetables/[id]

  • e.g. DELETE http://localhost:5000/vegetables/5TsEt-xfI

If there is a record where the ID matches, remove the resource from the array. Return a status code of 200.

Correct Response Body Example

{ "id": "5TsEt-xfI", "name": "turnip", "price": "0.79" }

If there is not a record where the ID matches, return an error with a status of 404 saying that the vegetable could not be found.

Incorrect Response Body Example

{ "message": "Could not find vegetable with ID of 1" }

PUT /vegetables/[id]

  • e.g. PUT http://localhost:5000/vegetables/5TsEt-xfI

If there is a record where the ID matches, validate the request body and then update the resource with the new information. Return a status code of 200.

Correct Request Body Example

{ "name": "turnip", "price": "0.79" }

Correct Response Body Example

{ "id": "5TsEt-xfI", "name": "turnip", "price": "0.79" }

If there is not a record where the ID matches, return an error with a status of 404 saying that the vegetable could not be found.

Incorrect Response Body Example

{ "message": "Could not find vegetable with ID of 1" }

If the request body does not include the "name" and "price" keys, or includes other keys, return the validation error.

Incorrect Request Body Example

{ "name": "turnip" }

Incorrect Response Body Example

{ "message": "Bad request" }

GET /fruits

  • e.g. GET http://localhost:5000/fruits

Return all fruits with a status code of 200.

Correct Response Body Example

[
  { "id": "p7pzzZxCX", "name": "banana", "price": "0.79" }
]

GET /fruits?name=[partial-query]

Note: This is not a new route!

  • e.g. GET http://localhost:5000/fruits?name="berr"

Return a list of all fruits where the query is included somewhere in the name.

Correct Response Body Example

[
  { "id": "H14ykcZcT", "name": "blueberries", "price": "2.99" },
  { "id": "faf84ZZNF", "name": "strawberries", "price": "3.99" }
]

If there are no fruits that match, just return an empty array.

Correct Response Body Example

[]

GET /fruits/[id]

  • e.g. GET http://localhost:5000/fruits/p7pzzZxCX

If there is a record where the ID matches, return the resource with a status code of 200.

Correct Response Body Example

{ "id": "p7pzzZxCX", "name": "banana", "price": "0.79" }

POST /fruits

  • e.g. POST http://localhost:5000/fruits

Validate the request body and then create a new resource with an ID. Return a status code of 201.

Correct Request Body Example

{ "name": "banana", "price": "0.79" }

Correct Response Body Example

{ "id": "p7pzzZxCX", "name": "banana", "price": "0.79" }

DELETE /fruits/[id]

  • e.g. DELETE http://localhost:5000/fruits/p7pzzZxCX

If there is a record where the ID matches, remove the resource from the array. Return a status code of 200.

Correct Response Body Example

{ "id": "p7pzzZxCX", "name": "banana", "price": "0.79" }

If there is not a record where the ID matches, return an error with a status of 404 saying that the banana could not be found.

Incorrect Response Body Example

{ "message": "Could not find banana with ID of 1" }

PUT /fruits/[id]

  • e.g. PUT http://localhost:5000/fruits/p7pzzZxCX

If there is a record where the ID matches, validate the request body and then update the resource with the new information. Return a status code of 200.

Correct Request Body Example

{ "name": "banana", "price": "0.79" }

Correct Response Body Example

{ "id": "p7pzzZxCX", "name": "banana", "price": "0.79" }

If there is not a record where the ID matches, return an error with a status of 404 saying that the banana could not be found.

Incorrect Response Body Example

{ "message": "Could not find banana with ID of 1" }

If the request body does not include the "name" and "price" keys, or includes other keys, return the validation error.

Incorrect Request Body Example

{ "name": "banana" }

Incorrect Response Body Example

{ "message": "Bad request" }

exercise-express's People

Contributors

bwreid avatar tworkman512 avatar

Watchers

 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.