Skip to content

Latest commit

 

History

History
129 lines (78 loc) · 2.75 KB

README.md

File metadata and controls

129 lines (78 loc) · 2.75 KB

Table of Contents

  1. dht22-API
  2. Requirements
  3. Setup
  4. GET and POST requests description
    1. GET request
    2. POST request

dht22-API

A simple API written in Go for the temperature and humidity dht22 sensor. It supports GET and POST requests

Requirements

  • Go 1.14 or higher
  • MongoDB
  • mongo-go-driver

OR

  • docker
  • docker-compose

Setup

Due to a license issue many Linux distributions removed MongoDB from their official repositories, as result it is easier to set up the project with Docker rather than compiling MongoDB ourselves.

  1. Install docker and docker-compose on Arch based distributions

    $ pacman -S docker docker-compose
    
  2. Get the source code

    $ git clone git@github.com:KNaiskes/dht22-API.git
    $ cd dht22-API
    
  3. Run project

    1. Start docker

      $ sudo systemctl start docker
      
    2. Run project

      It will take some time the first time you run this command as it will have to pull the Go and MongoDB images

      $ docker-compose up # You may have to run this command with sudo
      

      Visit localhost:8080/measurements to verify that everything work as they should, you are expected to see an empty list

GET and POST requests description

GET request

Path Result
/measurements Returns a list with all measurements or an empty list
/measurements/{id} Returns the one measurement with the specified {id} or 404
/measurements/{name} Returns all measurements from the sensor with the specified {name} or an empty list

POST request

POST request consists of three optional parameters (id is assigned automatically by the server).

Example of POST request with cURL

curl -d '{

    "name":"basement",
    "temperature":"17.25",
    "humidity":"21.33"

}' -H "Content-Type: application/json" -X POST http://localhost:8080/measurements