1
1
mirror of https://github.com/qfpl/applied-fp-course.git synced 2024-11-26 06:38:40 +03:00
applied-fp-course/level02
Sean Chalmers 959eb576aa Issue Fixes & More feedback driven development
Fixes: #15, #13, #14, #11, #8

Add the IDEAS to a 'Suggestions' section in the FUTURE_PLANS file.

* Updated the cabal instructions for level 03
* Removed the duplicated config loading in level 05
* Add the implementations for File.hs for levels 06 & 07
* Renamed the slightly misleading 'readObject' function
* Fixed the capitalisation of init and close DB functions between levels
  04 & 05.
2018-01-22 11:40:11 +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 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 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 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