1
1
mirror of https://github.com/qfpl/applied-fp-course.git synced 2024-11-29 16:55:12 +03:00
applied-fp-course/level02
Sean Chalmers cd77f68897 Merged PR for adding stack.yml files and typo fixes.
Merge branch 'master' of github.com:qfpl/applied-fp-course
2018-01-16 12:47:25 +10:00
..
bin Fix project restructure 2017-08-14 16:48:34 +10:00
src/FirstApp Fix a reference to the nicta IRC channel. Update some comments / formatting in Main.hs for level 2 and 3. 2017-12-13 15:37:06 +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 Updates based on course run feedback. 2018-01-16 12:36:57 +10:00
Setup.hs Added two stages. 2017-08-09 13:06:21 +10:00
stack.yaml Add stack.yaml files for all directories. 2018-01-10 10:33:56 +10: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 exec 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