haxe.Http example?

1,860 views
Skip to first unread message

simo

unread,
Dec 25, 2013, 7:24:32 AM12/25/13
to haxe...@googlegroups.com
Hello,

Where can I find examples about using haxe.Http ?
What I need to do, is to post a request to a server, and parse the response parameters sent by the server.

Any example on the topic would be very helpful, thanks!

Juraj Kirchheim

unread,
Dec 25, 2013, 7:41:36 AM12/25/13
to haxe...@googlegroups.com
This depends very much on the nature of the reponse.

Typically, between a Haxe client and Haxe server you will just use
Haxe remoting.

As for plain HTTP requests, this should give you the idea:
http://try.haxe.org/#fa2cE

Regards,
Juraj
> --
> To post to this group haxe...@googlegroups.com
> http://groups.google.com/group/haxelang?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Haxe" group.
> For more options, visit https://groups.google.com/groups/opt_out.

simo

unread,
Dec 25, 2013, 8:06:03 AM12/25/13
to haxe...@googlegroups.com
No, its not a haxe server, its rails server, but I've noticed that data retrieved at the example you've sent me has no parameters, but only string ..
So, for my case, I think I will let the server respond with a json based string, do you have other suggestion?

simo

unread,
Dec 25, 2013, 8:11:40 AM12/25/13
to haxe...@googlegroups.com
Also, is req.setParameter  the way to specify parameters sent to server?

Jason O'Neil

unread,
Dec 25, 2013, 8:16:21 AM12/25/13
to haxe...@googlegroups.com
Yes, and yes.

Example usage:

var req = new Http( "http://myserver.com/api/userinfo/" );
req.setParameter( "userID", "34" );
req.setParameter( "includeFriendList", "true" );
req.request( false ); // false=GET, true=POST

And yes, it's a good idea when working between different languages or frameworks to use GET/POST parameters for passing info to the API, and return either JSON or XML, with JSON generally being easier to work with... Rails can work this way fairly simply, then you just read the JSON on the client in your Haxe code.

Jason


--

Juraj Kirchheim

unread,
Dec 25, 2013, 8:20:56 AM12/25/13
to haxe...@googlegroups.com
You can use haxe.Json.parse or Xml.parse or whatever is appropriate to
process the data.

As for setParameter, it is a workable solution. It should be noted
though that setPostData will overwrite cause the parameters not to be
sent in fact. You could also be posting JSON strings to an endpoint.
In that case you could still specify parameters directly in the query
string of the URL.

Regards,
Juraj

Samir Sabri

unread,
Dec 25, 2013, 10:06:24 AM12/25/13
to haxe...@googlegroups.com

Thanks very much for info, what if I am sending to https ? Is there settings I have to do local side?

You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.

Jason O'Neil

unread,
Dec 25, 2013, 8:55:48 PM12/25/13
to haxe...@googlegroups.com
I believe you just use:

var req = new Http( "https://myserver.com/api/userinfo/" );

On JS / Flash you will have to worry about cross-domain policy etc.  On neko/c++ you will need to include the "hxssl" haxelib.


You received this message because you are subscribed to the Google Groups "Haxe" group.

Justin L Mills

unread,
Dec 26, 2013, 11:26:36 AM12/26/13
to haxe...@googlegroups.com
Simo

RE: Ruby Haxe remoting.

There is a Ruby target under way and while I don't think it implements
many standard haxe library features yet for the right Ruby version it
should work fine for basic functionality although I think it is behind
the c target, I expect it may take some work but you might be able to
compile the haxe remoting to Ruby and use it with your Rails code,
however it maybe too early. Certainly I would be interested to see it
done. It maybe quite dependent on ruby version that your currently
using, but I am sure that could be addressed by the author if you got
something running in a version that was compatible.

https://github.com/paulfitz/haxe.git

Like I said maybe a long short but if your willing to put some work in
quite exciting.

Best Justin



simo:
> No, its not a haxe server, its rails server, but I've noticed that data
> retrieved at the example you've sent me has no parameters, but only string
> ..
> So, for my case, I think I will let the server respond with a json based
> string, do you have other suggestion?
>
> On Wednesday, December 25, 2013 3:41:36 PM UTC+3, back2dos wrote:
>>
>> This depends very much on the nature of the reponse.
>>
>> Typically, between a Haxe client and Haxe server you will just use
>> Haxe remoting.
>>
>> As for plain HTTP requests, this should give you the idea:
>> http://try.haxe.org/#fa2cE
>>
>> Regards,
>> Juraj
>>
>> On Wed, Dec 25, 2013 at 1:24 PM, simo <as3...@gmail.com <javascript:>>
>> wrote:
>>> Hello,
>>>
>>> Where can I find examples about using haxe.Http ?
>>> What I need to do, is to post a request to a server, and parse the
>> response
>>> parameters sent by the server.
>>>
>>> Any example on the topic would be very helpful, thanks!
>>>
>>> --
>>> To post to this group haxe...@googlegroups.com <javascript:>
Reply all
Reply to author
Forward
0 new messages