WeatherStation backend with GraphQL goodies.
Once the repository is cloned (git clone https://github.com/javierdelgadofernandez/weatherstation
), you can either run directly on your machine (requires lein installed) or run it with Docker. In both cases, it will require a PostgreSQL dababase (check db.clj
to see details) running in the host. The server will start on port 3002
.
Using liningen
we will need only one command that will download the libraries and run the server:
lein ring server-headless
Simply build the container:
docker build -t weatherstation-be .
And run it:
docker run --network=host weatherstation-be
And from another terminal, we should be able to send data:
curl -XPOST localhost:3002/api/measure \
-H "Content-Type: application/json" \
-d '{"temperature": 23, "pressure": 22, "humidity": 20, "epoch": 3494701246000}'
Using the GraphQL
syntax but sending the request as JSON
:
If we do not specify either from
or to
, the server returns the last measure:
curl -XPOST 'localhost:3002/graphql' \
-H "Content-Type: application/json" \
-d '{"query": "query { measures {temperature,humidity,epoch}}"}'
With parameters from
and to
we can specify a date range to retrive:
curl -XPOST 'localhost:3002/graphql' \
-H "Content-Type: application/json" \
-d '{"query": "query { measures(from: 1494701245000, to:1494701247000) {temperature,humidity,epoch}}"}'
Or:
curl -XPOST 'localhost:3002/graphql' \
-H "Content-Type: application/json" \
-d '{"query": "query { measures(from: 1494701245000) {temperature,humidity,epoch}}"}'
Or:
curl -XPOST 'localhost:3002/graphql' \
-H "Content-Type: application/json" \
-d '{"query": "query { measures(to: 1494701245000) {temperature,humidity,epoch}}"}'