HTTP GET request for data and post to website

#1

Hi all,

I need to create an application that will accept following:

  • an http GET request to http://your-node-red-instance/time that returns a JSON document containing the current time on the NodeRED server

  • an http GET request to http://your-node-red-instance/random that returns a JSON document containing a generated random number

  • an http GET request to htp://your-node-red-instance/page that returns an http page that shows:

  1. when the last time was requested
  2. when the last random number was requested
  3. the value of the last random number generated

It is important that the time and random number reported by the /page request match exactly the values last returned from /time and /random requests, so I will need to use facilities available in Node-RED to hold these values.

The time must be formatted to have a 2-digit hour in the 24-hour clock.

The response must have a Content-Type of 'application/json' to be properly parsed as a JSON document in {"random" : number}

For example, if the last request to the /time page as at 4 minutes past 1 in the afternoon and the last request to the /random page returned 4 and was made at 23 minutes past 10 in the morning the response should be:

"Time last server time request received at 13:04
Last random number request returned 4, which was received at 10:23"

May I have the code in txt that I can import to Bluemix.

How can i build a random delayed trigger loop?
#2

That sounds like a homework question
Is this part of an assessment you have been set?

#3

I am taking a node-red training but I have no background in javascript, so now in a rush to pick up javascript but need to meet the deadline to submit assignment. I'd finished some assignments but this one cannot figure out (cannot find similar example to learn).

#4

The cookbook has some great http examples https://cookbook.nodered.org

#5

This from the Coursera Intro to IoT course.

Please use the Coursera forum for questions. It is against the Coursera honor code to get other people to complete your assignment for you.