Sign In Register

How can we help you today?

Start a new topic
Answered

httpSender Examples

Hi all


I'm new to looking at gamesparks - Struggling to find many examples of some of the methods available.


Coming from a node.js and javascript background i'm struggling to see how some things pull together.


var httpSender = Spark.getHttp("http://somehost")


So i'm assuming httpSender will get the response, what if it fails?

How can I access the result?

Where is best to execute this? 


I want to run everything from cloud code and happy that events are effectively classes but i'm still not quite understanding how some of the less well documented aspects such as httpRequest fit into the stack.


Thanks for your help


fraser





Best Answer

Hi Fraser,


You can access most results by making them a variable, like:


    

//Gets a random string

var response = Spark.getHttp("http://www.random.org/strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new").get().getResponseString(); 

  

From there you can see the data by referencing the response.


You can manipulate the data using the variable or pass it on to the Response using Spark.setScriptData like:

  

//Gets a random string

var response = Spark.getHttp("http://www.random.org/strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new").get().getResponseString(); 

//Check for whatever their error response will be
if(response !== "404 error"){
	Spark.setScriptData("Random String", response);
}
 

 


Shane

1 Comment

Answer

Hi Fraser,


You can access most results by making them a variable, like:


    

//Gets a random string

var response = Spark.getHttp("http://www.random.org/strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new").get().getResponseString(); 

  

From there you can see the data by referencing the response.


You can manipulate the data using the variable or pass it on to the Response using Spark.setScriptData like:

  

//Gets a random string

var response = Spark.getHttp("http://www.random.org/strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new").get().getResponseString(); 

//Check for whatever their error response will be
if(response !== "404 error"){
	Spark.setScriptData("Random String", response);
}
 

 


Shane

Login to post a comment