Skip to content

Instantly share code, notes, and snippets.

@Maxim-Filimonov
Last active June 12, 2018 04:12
Show Gist options
  • Save Maxim-Filimonov/bed1dab5bb14f954fe252281d6789a7e to your computer and use it in GitHub Desktop.
Save Maxim-Filimonov/bed1dab5bb14f954fe252281d6789a7e to your computer and use it in GitHub Desktop.
Express.js assignments

Grocery List API

Build an API for grocery list mobile app.

POST /groceries/

Example request:

POST /groceries

{
  title: "Milk",
  category: "Milk based products",
  amount: 1
}

Example response

201

{
  id: 2,
  title: "Milk",
  category: "Milk based products",
  amount: 1,
  purchased: false
}

GET /groceries

Example request

GET / {}

Example response

{ groceries: [ { id: 1, title: "Eggs", category: "General", amount: 12, purchased: false }, { id: 2 title: "Milk", category: "Milk-based products", amount: 1, purchased: true } ] }

PATCH /groceries/

Example request

PATCH /groceries/2/

{purchased: true}

Example response

{
  id: 2,
  title: "Milk",
  category: "Milk based products",
  amount: 1,
  purchased: true
}

Grocery List API v2

Now we going to make our groceries list a bit more complicated by introducing pantry - pantry is a list of items that is in your home already.

Whenever item is purchased at groceries we add it to pantry.

Whenever item is removed from pantry we add it to groceries.

Grocery -> purchased -> add to pantry

Pantry -> delete -> add to grocery

I'd advice you to write tests to capture the requirements of moving between pantry and groceries.

POST /pantry/

Example request:

POST /pantry

{
  title: "Milk",
  category: "Milk based products",
  amount: 1
}

Example response

201

{
  id: 2,
  title: "Milk",
  category: "Milk based products",
  amount: 1
}

GET /pantry

Example request

GET / {}

Example response

{
groceries: [
{
  id: 1,
  title: "Eggs",
  category: "General",
  amount: 12,
  purchased: false
},
{
  id: 2
  title: "Milk",
  category: "Milk-based products",
  amount: 1,
  purchased: true
}
]
}

DELETE /pantry/:id

Example request

DELETE /pantry/2/

Example response

200

GET /inventory

Example request

GET /inventory

Example response

{
pantry: [{
  id: 2,
  title: "Milk",
  category: "Milk based products",
}],
groceries: [{
  id: 1,
  title: "Eggs",
  category: "General",
  amount: 12,
  purchased: false
},]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment