Exercise #06 - Counter

Write a server that exposes two routes:

Keep the state of a counter (starting from 0). The counter can only be increased.

    GET /current-count
    >>> expected 0

    POST /increase

    GET /current-count
    >>> expected 1

    POST /increase
    POST /increase

    GET /current-count
    >>> expected 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")()

// Mutable state!
let currentState = 0

app.post("/increase", (req, res) => {
  currentState++
  res.send("ok")
})

app.get("/current-count", (req, res) => {
  res.send('' + currentState)
})

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

        

Where to get help

Got stuck? Don't worry! Join the discussion on Github (issue #6). 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!