O'Reilly logo

Full Stack Web Development with Raspberry Pi 3 by Soham Kamani

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding the required APIs

Just like in the previous section, we will need to start by adding the APIs to get the readings and their average for a certain time period:

    app.get('/temperature/range', function (req, res) {
      /**
       * Here, the "start" and "end" datetimes for the range     of readings are
       * expected to be received through the query parameters.     This is spllied as part
       * of the URL request
       */
      const {start, end} = req.query

      /**
       * The "fetchReadingsBetweenTime" method is called,     which returns an array of results, which we return as     JSON to the client side
       */
      databaseOperations.fetchReadingsBetweenTime    ('temperature', start, end, (err, results) => {
        if (err) {
          console.error(err)
          return res.status(500).end()
        }
       res.json(results)
      })
    })

    app.get ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required