Making haxelib api calls

Howdy all,

Does anyone know how you can make remoting calls to haxelib (http://lib.haxe.org:80/api/3.0/index.n) without having to use neko / haxelib client? Ive tried things like:

        var cnx = haxe.remoting.HttpAsyncConnection.urlConnect("http://lib.haxe.org:80/api/3.0");
        cnx.call(["search", "haxeui-core"], function(d) {
            trace(d);
        });

And just get a “moved permanently” error - is there any documentation anywhere of a way to acheive this sort of stuff? Reading the haxelib source is making my eyes bleed :smiley:

Cheers,
Ian

The moved permanently redirects to http://lib.haxe.org/api/3.0/ which gives me a result, though it still errors.

Having a file with (haxelib/SiteApi.hx at development · HaxeFoundation/haxelib · GitHub)

interface HaxelibApi {
	public function search(word:String):List<{id:Int, name:String}>;
}

and

class SiteProxy extends haxe.remoting.Proxy<HaxelibApi> {}

function main() {
	final site = new SiteProxy(haxe.remoting.HttpConnection.urlConnect("http://lib.haxe.org:80/api/3.0").resolve("api"));
	trace(site.search("haxeui-core"));
}

worked.

Good luck reading the haxelib source, you’ll need it :smiley:

1 Like

Thanks! Im getting this now though:

SiteProxy.hx:3: characters 0-58 : Could not load proxy module HaxelibApi (try using absolute path)

EDIT: any chance you could zip and post your entire project?

Had that error too, I think it ignores imports. Also had an error when trying to have it in the same file, so had to put it in another.

Here’s a full project: GitHub - ibilon/haxelibApi

1 Like

Nice one, thanks Valentin :slight_smile:

It compiles now, but throws this at runtime:

Uncaught TypeError: Cannot read property 'substr' of null
    at Function.HxOverrides.substr
    at haxe_remoting_HttpConnection.call

This is under js

EDIT: so i think the issue is that its trying to use a sync http, and under nodejs that isnt a thing (or doesnt seem to be looking at the code):

		#if (js && !nodejs)
			h.async = false;
		#end

I tried to use HttpAsyncConnection but dont seem to be getting anywhere

EDIT2: Ok, so i can get it compile by using HttpAsyncConnection and haxe.remoting.AsyncProxy:

class HaxelibApi extends haxe.remoting.AsyncProxy<data.haxelib.SiteApi> {
	public static function connect() {
		return new HaxelibApi(haxe.remoting.HttpAsyncConnection.urlConnect("http://lib.haxe.org/api/3.0/").resolve("api"));
	}
}

And changing the call to something like:

            _api = HaxelibApi.connect();
            _api.search("haxeui-core", function(list:List<{id:Int, name:String}>) {
                trace(list);
            });

however, now i get this at runtime:

haxe_ValueException {message: "Invalid path ''", __previousException: undefined, __nativeException: haxe_ValueException, value: "Invalid path ''"}
message: "Invalid path ''"
value: "Invalid path ''"

FINAL EDIT!!! Ok, so ignore more! :smiley:

I had edited HttpAsyncConnection yesterday to hardcode things… doh! Works fine now… sorry for the spam!

Couple years ago I tried something similar. In case you don’t want to deal with the remoting macros, you can use haxe.Serializer directly and send a request like here:

The reponse starts with ‘hxr’ and the rest can de deserialized:

2 Likes

Yeah, nice one… now i have it working using remoting, i can get payloads etc and have managed to replicate a request in postman that seems to work fine… So as you point out, it would be fairly trivial i think to have it working with just raw http and get rid of the macros + hx3compat lib… thanks for the info, ill certainly likely use yours a starting point if / when i decide to go down that route.

Cheers,
Ian