measurementsTH-API

command module
v0.0.0-...-3b71f4f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2021 License: GPL-3.0 Imports: 4 Imported by: 0

README

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 [email protected]: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

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL