1
1
mirror of https://github.com/qfpl/applied-fp-course.git synced 2024-11-26 14:43:53 +03:00
applied-fp-course/level02
2018-02-09 11:33:59 +10:00
..
bin Fix project restructure 2017-08-14 16:48:34 +10:00
src/FirstApp Minor adjustments. Fix some remaining capitalisation issues for runDB 2018-02-09 11:33:59 +10:00
changelog.md change changelog files to lowercase 2017-09-01 11:17:26 +10:00
default.nix Overhauled nix file setup to be more like the other QFPL projects. 2017-09-18 10:14:29 +10:00
level02.cabal Updates based on course run feedback. 2018-01-16 12:36:57 +10:00
level02.nix Overhauled nix file setup to be more like the other QFPL projects. 2017-09-18 10:14:29 +10:00
LICENCE update copyright notice 2017-09-12 11:51:26 +10:00
README.md Issue Fixes & More feedback driven development 2018-01-22 11:40:11 +10:00
Setup.hs Added two stages. 2017-08-09 13:06:21 +10:00
stack.yaml Update to stackage LTS 10 (GHC 8.2.2) 2018-01-31 12:20:33 +11:00

Level 02

This level focuses on using our application's requirements to design some data structures, and how we can then use those data structures to guide construction.

By using these data structures we provide a mechanism for utilising the compiler as a pair programmer. It will inform us when we've forgotten to handle a given path, tried to use information we don't have access to, or haven't validated our inputs sufficiently.

To build this REST application we're going to need some requirements:

Requirements

We have a WebThing(TM) somewhere and we would like, for some unknown reason, to be able to add comments to various topics on this WebThing(TM).

"Spec"

This will be a REST only application, there won't be any HTML involved.

Let's pretend we've completed a dozen specification meetings with our Project Manager, resulting in the specification below:

We have to be able to:

  • Comment on a given topic
  • View a topic and its comments
  • List the current topics

So we will work towards building the following routes:

# To comment on a given <topic>
POST /<topic>/add

# To view all the comments on a given <topic>
GET /<topic>/view

# To list all the current topics
GET /list

The starting point for this exercise is the src/FirstApp/Types.hs.

Running the program:

# Using cabal
$ cabal run level02-exe

# Using stack
$ stack exec level02-exe

Accessing the program:

Using curl:

# Running a POST

# Valid request
$ curl -XPOST -v localhost:<port>/puppies/add -d "Puppies are awesome."

# Invalid request (should trigger an error in the program)
$ curl -XPOST -v localhost:<port>/puppies/add

# Running a GET
$ curl -XGET -v localhost:<port>/puppies/view
$ curl -XGET -v localhost:<port>/list