This repository contains a simple example of how to use the
servant-checked-exceptions
library.
The example has a simple API, representing a simple database of locations, where each location has a unique integer ID and a unique name.
The API provides operations to add new locations, as well as to find existing locations based on ther IDs or names.
Each endpoint is capable of throwing exceptions, as declared with the
Throws
combinator. Each exception type corresponds to a specific HTTP error code.
$ stack build
$ stack exec server
$ stack exec client -- addLocation "Cambridge"
Location {locationId = 0, locationName = "Cambridge"}
$ stack exec client -- addLocation "Oxford"
Location {locationId = 1, locationName = "Oxford"}
$ stack exec client -- addLocation "Boston"
Location {locationId = 2, locationName = "Boston"}
$ stack exec client -- addLocation "Taipei"
Location {locationId = 3, locationName = "Taipei"}
$ stack exec client -- addLocation "A"
LocationNameTooShortError
$ stack exec client -- addLocation "****"
LocationNameHasInvalidCharsError
$ stack exec client -- findLocationById 0
Location {locationId = 0, locationName = "Cambridge"}
$ stack exec client -- findLocationByName Oxford
Location {locationId = 1, locationName = "Oxford"}
$ stack exec client -- findLocationById 1000
NoMatchingLocationError
$ stack exec client -- findLocationByName Utopia
NoMatchingLocationError
$ stack exec swagger | json_pp | less