How to send HTTP GET requests to use an online leaderboard service?

Hi !
Is it possible to use the service offered by this site in Armory ?
Site : http://dreamlo.com/
The service is available through HTTP GET requests : http://dreamlo.com/developer
Everything seems so easy, but how to use it in Armory ?
Having leader-boards in our games would be so nice…

Hi, I have no experience with networking, but this might help you:


API:
https://api.haxe.org/sys/net/Socket.html

Then you can parse the received data as json (e.g.)

Thanks @timodriaan, it will sure help.

If someone could provide a short working example, it would be very nice.

I was wrong in my last answer, sockets are not the way to go here. There is this library that allows you to create http requests: https://github.com/tbrosman/haxe-rest-client

Just clone or download and unzip it, put it in your libraries folder and you’re ready to go. Unfortunately, it doesn’t seem to work with Krom.

Example trait (note that it didn’t work to set scoreboard entries, I don’t know why):

package arm;

import restclient.RestClient;

class Scoreboard extends iron.Trait {

	public function new() {
		super();

		notifyOnInit(function() {
			// I could not get this working... RestClient.put() also didn't work, the 
			// website says you should use get requests all the time.
			RestClient.get("http://dreamlo.com/lb/[your-private-code]/add/Test/100");
			RestClient.get("http://dreamlo.com/lb/[your-private-code]/add/Test/120");
			RestClient.get("http://dreamlo.com/lb/[your-private-code]/add/Test2/90");

			// Get the scoreboard as json
			RestClient.getAsync(
				"http://dreamlo.com/lb/[your-public-code]/json",
				function(result) {
					trace(result);
				}
			);
		});
	}
}

2 Likes

Networking is impossible on Krom: https://github.com/Kode/Krom/issues/100

1 Like

What a bad new :frowning:
Are you absolutely certain it can’t be done ? Could it work when exporting to html5 ?
If really nothing can work, what is missing ?

The html5 target isn’t Krom, so that works, yes.

I confirm it could work on HTML5 :slightly_smiling_face:
HTTP request does not work in Krom, but work in HTML5.

When using this haxe trait on HTML5 it returns well your IP :

var http = new haxe.Http("https://api6.ipify.org?format=json");

		http.onData = function (data:String) {
		  var result = haxe.Json.parse(data);
		  trace('Your IP-address: ${result.ip}');
		}

		http.onError = function (error) {
		  trace('error: $error');
		}

		http.request();

So… in theory, High scores tables are possible in HTML5.

Now, the UI will be the hard task…