I seem to not be able to find any documentation on how to handler http incoming requests for agents.
Here is what I have:
http.onrequest(function) can be used to have a function called when a http request is made to the agent.
The function has two parameters (HttpRequest, HttpResponse)
The values within each of these tables to not appear documented.
Request has a body, and you call send on the response. Other than that, it appears to be a black box.
** End goal **
I’m trying to grab the GET parameters from a request.
Ah, have you found our forthcoming new documentation site, maybe? That one’s not quite complete yet. Right now the callback function is documented only at the old site: http://devwiki.electricimp.com/doku.php?id=electricimpapi:http:handler
Thanks Peter, that was what I needed.
Now, back to awesome impness.
Inline functions are really cool when you learn how to use them.
First of all, thank you guys for such awesome device and API. I love the imp! Processing that for Arduino I had to do in some app on the web I can do now in the agent. Also, when I needed to check some value in Arduino I had to have it connected to the computer, now I just use the server.log magic and it’s there in the IDE. Really, love it!
I do have a question: I can get the query params from a GET request but how do I do it from a POST request? I used postman to send a POST to my agent URL and I know it works because I get the right response back. But when I try to get the request params I don’t get anything. Both these for loops print nothing:
` foreach(idx,val in request.query)
foreach(val in request.query)
What am I doing wrong?
Thanks for all your help!
res.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
res.header("Access-Control-Allow-Headers", "origin, x-csrftoken, content-type, accept");
local keys = split(request.body,"&");
local keyA = split(keys,"=");
I written some tutorials using JQmobile might be of help http://industrialinternet.co.uk/eimp/t2_digital_out/index.html
local keys = split(request.body,"&"); local keyA = split(keys,"="); server.log("keyA:"+keyA);
That’s what http.urldecode() is for:
local keys = http.urldecode(request.body); foreach(idx,val in keys) server.log("index="+idx+" value="+val+"\ ");
Thank you so much, @peter and @controlCloud. It works great! You are awesome, thanks again for all the help. And for the tutorial link, @controlCloud.