This is a simple application built to learn the Yesod Haskell web framework. It uses SQLite and yesod-persistent to provide a persistent storage layer. An even simpler Yesod web application is available at artemmavrin/yesod-hello-world
The application itself is a simple floating point calculator that supports variables, which are stored in a SQLite database (the environment).
This project uses stack
for building, running, and documentation.
Start the server locally at http://localhost:3000
using
stack run
We start with a fresh environment:
$ curl http://localhost:3000/variables
[]
Next, we assign a = 10
and b = -0.5
,
$ curl http://localhost:3000/variables -H 'Content-Type: application/json' -d '{"a": 10, "b": -0.5}
and query the variables again
$ curl http://localhost:3000/variables
[{"created":"2022-11-29T07:15:39.591669Z","name":"a","updated":"2022-11-29T07:15:39.591669Z","value":10},{"created":"2022-11-29T07:15:39.59253Z","name":"b","updated":"2022-11-29T07:15:39.59253Z","value":-0.5}]
We can query individual variable values using either
$ curl 'http://localhost:3000/variables?name=a'
[{"created":"2022-11-29T07:15:39.591669Z","name":"a","updated":"2022-11-29T07:15:39.591669Z","value":10}]
or
$ curl http://localhost:3000/variables/a
{"created":"2022-11-29T07:15:39.591669Z","name":"a","updated":"2022-11-29T07:15:39.591669Z","value":10}
Next we update the value of a
to 100
curl -X PUT http://localhost:3000/variables/a -H 'Content-Type: application/json' -d '{"value": 100}'
and confirm the update
$ curl http://localhost:3000/variables/a
{"created":"2022-11-29T07:15:39.591669Z","name":"a","updated":"2022-11-29T07:21:36.719543Z","value":100}
Lastly, we evaluate the expression 1+2*(a*b)/(b-3)
$ curl -X POST http://localhost:3000 -H 'Content-Type: application/json' -d '{"expr": "1+2*(a*b)/(b-3)"}'
{"value":29.571428571428573}