Haxe for webapplication development

205 views
Skip to first unread message

Kaj88

unread,
Aug 16, 2015, 5:40:06 PM8/16/15
to Haxe
Hallo,

I am quite new to webdevelopment. I took my first steps with Java Servlets and had some experience with the Google Web Toolkit. The Haxe language is one of the best languages I started learning so far, so I would like to give it a try for our web based next project.

The documentation from haxe.org on the haxe language itself helped me a lot to get a quick jump into the matter. Then I tried to figure out how to write a "Hallo World" welcome page generated by neko binary code. All I've achieved thus far is to run the nekotools development server. From the Haxe API I found this page:
http://api.haxe.org/neko/Web.html
How can I print something to the html response? The cacheModule function description says "Set the main entry point function used to handle requests." but the function which is accepted cannot receive any parameter nor can it deliver any value (both Void). So ... where should I write the generated html to? I could not find any method delivering something like a response instance or similar.
Is there a tutorial somewhere to explain the basics?

Thanks a lot in advance =)

Juraj Kirchheim

unread,
Aug 17, 2015, 7:13:27 AM8/17/15
to haxe...@googlegroups.com
You will have to use Sys.print to print output.

Best,
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/d/optout.

Message has been deleted

Kaj88

unread,
Aug 17, 2015, 7:36:15 AM8/17/15
to Haxe
uh... I am kind of stunned... o.O
it's so freakn easy o.O
hmm... gonna investigate this further.

Thanks a lot <(^_^)>

Juraj Kirchheim

unread,
Aug 17, 2015, 7:38:53 AM8/17/15
to haxe...@googlegroups.com
No, you have made yourself clear. It only seams that Java spoiled you to expect all answers to be complex. Here is a full example of a hello world server:

  class Main {
    static function main()
      Sys.println('<html><body>hello world from ${neko.Web.getURI()} with ${neko.Web.getParams()} using ${neko.Web.getMethod()}</body></html>');
  }

Run it like so:

  haxe -main Main -neko index.n && nekotools server -rewrite

Does that make it clear?

You can get everything with neko.Web and output is as simple as Sys.print. As for the rest, I suggest you make yourself familiar with SPOD (http://old.haxe.org/manual/spod) for persistence and dispatch (http://old.haxe.org/manual/dispatch) for routing.

Best,
Juraj

On Mon, Aug 17, 2015 at 1:17 PM, Kaj88 <kam...@gmx.de> wrote:
Maybe I have not made clear enough what I tried to achieve.

The goal is to send a simple http response with generated html content with haxe by using the nekotools development server (should work with mod_neko for apache too).

The remoting package (explained here: http://haxe.org/manual/std-remoting-connection.html) offers a way of client/server communication which seems to be higher level, like the Java Remote Method Invocation library. I would like to use lower level communication via pure HTTP client request and server response (POST/GET) methods.

Juraj Kirchheim

unread,
Aug 17, 2015, 7:54:04 AM8/17/15
to haxe...@googlegroups.com
Oh, and to clarify cacheModule: What it does is to handle all subsequent requests with the function you provide, while maintaining state.

Example:

class Main {
  static function main() {
    var x = 0;
    function serve()
      Sys.println(x++);
    serve();
    neko.Web.cacheModule(serve);
  }
}

If you comment out the last line, the response is always 0. If you don't, it will grow.

Best,
Juraj

Kaj88

unread,
Aug 17, 2015, 9:51:39 AM8/17/15
to Haxe
Ok, big thanks goes to you Sir. Your first reply made it clear for me, looks like I typed so slowly that I could not recognize your reply. After I read your first reply and trying out stuff I deleted my second post. Thankyou again for the further links, they are very helpul indeed.

Thomas Purnell

unread,
Feb 21, 2016, 7:08:08 AM2/21/16
to Haxe
Just wanted to thank you for your simple demonstration of neko.Web.cacheModule(), I've been trying to work out how to use this functionality from haxe directly for some hours. Cheers!
Reply all
Reply to author
Forward
0 new messages