Exercise #04 - String manipulation

Write a server that exposes a /string-manipulation route.
The body of the response is going to be a statement, like I think I could survive only on pizza..
If the statement begins with I'm positive, it should be replaced with the more conservative I think -- return the statement unchanged otherwise.

    POST /string-manipulation
    I think I could survive only on pizza.
    >>> expected "I think I could survive only on pizza."

    POST /string-manipulation
    I'm positive winter is the best season.
    >>> expected "I think winter is the best season."
  

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("/string-manipulation", (req, res) => {
  let result
  const body = req.body.toString()
  const search = "I'm positive"

  if (body.slice(0, search.length) === search) {
    result = "I think" + body.substr(search.length)
  }
  else {
    result = body
  }

  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 #4). 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!