Exercise #03 - Case match

Write a server that exposes a /case route.
The body of the request is going to be a number (for example 3) which you should return "spelled out" (three)

    POST /case
    1
    >>> expected "one"

    POST /case
    2
    >>> expected "two"
  
Only cover numbers from 1 to 3.

It looks like your server isn't up. This page expects your Haskell application to be listineing on http://localhost:7879.
If you're unsure on how to proceed, read more on how to setup your Local dev environment to complete the exercises.

Refresh the page to run the tests again.

Reference node.js implementation

          
const app = require("express")()
const bodyParser = require("body-parser")

app.use(bodyParser.raw({ type: "*/*" }))

app.post("/case", (req, res) => {
  let result

  switch (req.body.toString()) {
    case "1":
      result = "one"
      break
    case "2":
      result = "two"
      break
    case "3":
      result = "three"
      break
    default:
      result = "What am I, a mathematician?"
  }

  res.send(result)
})

console.log("Starting server...")
app.listen(7879)

        

Walkthrough video

Here's a video of me going through the exercise, from scratch! 🌵

Where to get help

Got stuck? Don't worry! Join the discussion on Github (issue #3). It might be that the exercise could be clearer or there's something you really can't wrap your head around. That's totally fine! 🙂

You can also have a look at my solution. No shame in having a peek. 🧐
But do share your thoughts on the exercises, it would be really helpful!