Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 129 lines (101 sloc) 4.156 kB
1791e3d Added a haXe remoting adapter with documentation
Yariv Sadan authored
1
2 <erl>
3
4
5 box(Str) ->
6 {'div',[{class,"box"}],
7 {pre,[], yaws_api:htmlize(Str)}}.
8
9 tbox(T) ->
10 box(lists:flatten(io_lib:format("~p",[T]))).
11
12
13 ssi(File) ->
14 {'div',[{class,"box"}],
15 {pre,[],
16 {ssi, File,[],[]}}}.
17
18 ss(A, File) ->
19 {ok, B} = file:read_file(
20 filename:join([A#arg.docroot, File])),
21 box(binary_to_list(B)).
22
23
24
25 out(A) ->
26 [{ssi, "TAB.inc", "%%",[{"haxe_intro", "choosen"}]},
27 {ehtml,
28 {'div', [{id, "entry"}],
29
30 [{h1, [], "haXe remoting"},
31
32 {p, [],
33 ["The yaws_rpc module has a haXe remoting adapter that enables "
34 "Yaws to respond to respond to "
35 "RPC requests from a client written in ",
36 {a, [{href, "http://www.haxe.org"}], "haXe"},
37 ". haXe is a versatile open source language that compiles to "
38 "Flash, Javascript and NekoVM. With haXe, You can use "
39 "write advanced clients for your Yaws backend without "
40 "suffering with Javascript and/or Actionscript. "
41 "For more information on haXe, visit ",
42 {a, [{href, "http://www.haxe.org/intro"}], "www.haxe.org/intro"}, "."]},
43 {p, [],
44 ["Implementing the server side of a haXe remoting interaction "
45 "in Yaws is very similar to the one described in the ",
46 {a, [{href, "json_intro.yaws"}], "Ajax/JSON RPC"}, " page. "
47 "Most of the action takes place behind the scenes inside the "
48 "the yaws_rpc module. The same types (array, struct, number "
49 "and string) work for haXe remoting as for JSON RPC. "
50 "There are just a few new things to keep in mind when using "
51 "haXe remoting: "
52 ]},
53 {ol, [],
54 [
55 {li, [], {p, [], "Class objects and enums work with standard "
56 "haXe remoting, but are not supported in Yaws. "
57 "You should therefore rely on anonymous objects and "
58 "signatures when designing your haXe remoting calls."}},
59 {li, [], {p, [], "A Yaws RPC handler can \"throw an exception\" "
60 "by returning {exception, Obj}, where Obj is any valid "
61 "haXe remoting value."}},
62 {li, [], {p, [], "haXe remoting has a few extra "
63 "values, expressed by the atoms 'infinity', 'neg_infinity' "
64 "and 'nan', corresponding to infinity, negative infinity "
65 "and 'not a number.'"}}
66 ]
67 },
68 {p, [], "Following is an example demonstrating the use of haXe "
69 "remoting in yaws. The first code segment is the haXe client "
70 "code, which invokes the 'echo' method in haxe_sample.yaws "
71 "and displays the result:"},
72 ss(A,"haxe_sample.html"),
73 {p, [], ["On the server side, we have the file haxe_sample.yaws "
74 "with the following code: "]},
75 ss(A, "haxe_sample.yaws"),
76
77 {p,[], "The two important lines on the server side are:"},
78 {ol,[],
79 [
80 {li,[],
81 {pre,[],"yaws_rpc:handler(A1, {haxe_sample, respond})."}},
82 {li,[],
83 {pre,[],"respond(State, {call, echo, Value} = _Request)"}}]},
84
85 {p,[],
86 "The first line tells Yaws to forward all RPC calls (this "
87 "includes both haXe remoting and JSON RPC calls -- remember that "
88 "the yaws_rpc module handles both RPC mechanisms transparently) "
89 "to the \"respond\" function in the \"haxe_sample\" module. "},
90 {p, [],
91 "The second line tells Yaws to invoke this 'respond' function "
92 "when the client requests the method 'echo', while passing "
93 "the new state variable as the first argument to 'respond'."
94 "You should duplicate this line for every RPC method you "
95 "wish to implement, replacing 'echo' with the method's name."},
96 {p, [],
97 "yaws_rpc optionally handles sessions for both JSON RPC and "
98 "haXe remoting. To use sessions, invoke yaws_rpc:handler_seesion "
99 "as shown in the JSON RPC documentation page."},
100
101 {p, [],
102 "If the response is in the form of {expression, Obj}, "
103 "where Obj is any valid haXe remoting type, then the haXe client "
104 "will invoke the 'onError' handler, with Obj passed as the "
105 "parameter."},
106 {p, [],
107 "As with JSON RPC, both request and response values can be "
108 "composed of nested tuples of the form"},
109 box("{array, [Obj,...]}"),
110 {p, [], "and/or "},
111 box("{struct, [{prop, Val}...]}"),
112 {p, [], "Now go have fun! :)"}
113 ]}},
114
115 {ssi, "END2",[],[]}
116 ].
117
118
119
120
121 </erl>
122
123
124
125
126
127
128
Something went wrong with that request. Please try again.