Hi,
I am trying to better understand the syntax ?led=1. I search the Forum and the web but didn’t find a description.
Is ? the “query” indicator? I get the led part but what if I want to submit a variable instead of a bool of 1 or 0? I also didn’t find a description of this in the Squirrel code; or did I overlook something?
You can pull out each individual value in your http.onrequest handler like so:
`http.onrequest(function(req, resp) {
local val1 = null;
local val2 = null;
local val3 = null;
// check if val1 is in the request's query
if ("val1" in req.query) {
val1 = req.query["val1"];
}
// check if val1 is in the request's query
if ("val2" in req.query) {
val2 = req.query["val2"];
}
// check if val3 is in the request's query
if ("val3" in req.query) {
val3 = req.query["val3"];
}
// do stuff with the query parameters:
server.log("val1 = " + val1);
server.log("val2 = " + val2);
server.log("val3 = " + val3);
// send a response
resp.send(200, "OK");
When you see variables in a URL, example: mysite.com/?page=14&category=5 …
that is an example of “GET”, where the website “gets” the variable(s) contained in the URL.
The alternative is “POST”, where the server-side script or agent “posts” the variables to the website within the packet (header, whatever). You don’t see the variables in the URL.
There are valid uses for GET and POST, and which you choose depends on your application or personal preference.
If you ever get into website development (server-side, such as PHP, Perl, or ASP), you’ll be using these for everything, and to go a step further, the server can use .htaccess, which is able to do more stuff with variables. This forum you’re using now probably uses .htaccess rewrite rules to convert the /various items/ in the URL (within the forward slashes) into something the program understands.
Just about anything can be given to a server or agent in this case. You could tell the agent what your name is and the imp could do something with that …