Skip to content

Instantly share code, notes, and snippets.

@mohammed-ali-1
Created March 12, 2019 14:29
Show Gist options
  • Save mohammed-ali-1/adb947050211c6011e0783084117fe4a to your computer and use it in GitHub Desktop.
Save mohammed-ali-1/adb947050211c6011e0783084117fe4a to your computer and use it in GitHub Desktop.
OpenWhisk web action that returns the latest ten entries to the readings database
function action(args) {
var request = require('sync-request');
var res = request(
'GET',
'http://COUCHDB_HOST:COUCHDB_PORT/readings/_all_docs?limit=10&include_docs=true&ascending=true'
);
var readings = JSON.parse(res.getBody().toString()).rows.map(elem => elem.doc.reading);
return {
body: readings
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment