Can some explain this line of code
Hello,
I'm following a RUBY code and writing a small script in php that will accept post request (json) and show values. However, the following line puzzles me - what does params["payload"] is doing ?
params = CGI::parse(post_body)
digest = Digest::SHA1.hexdigest(params[“payload”].to_json+secret_key)
{
"payload": {
"useriden": "900af657a65e",
"score": 50,
"Average": 25
},
"signature": "af886289"
}
Hi,
params is a json-blob that "basically" comes from the users browser. So for a HTTP GET request, if someone visits a URL like: /users?something=test&name=john - then params will look like:
{
something: "test",
name: "john"
}
The same basically goes for a HTTP POST request.
So params["payload"] in your example, references the content within:
"payload": {
"useriden": "900af657a65e",
"score": 50,
"Average": 25
},
so { useriden: "900af657a65e", score: 50, average: 25 }
I hope that makes sense? It's essentially data that hits the ruby backend via a HTTP request.