1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
{% extends "layout.html" %}
{% block body %}
<h2>Square Variant 1</h2>
<p>
Square a number by doing a HTTP/GET against
a REST-like URL that includes the number to square.
<ol>
<li><a href="square/3">square/3</a></li>
<li><a href="square/10">square/10</a></li>
<li><a href="square/2323">square/2323</a></li>
</ol>
</p>
<h2>Square Variant 2</h2>
<p>
Square a number by doing a HTTP/POST from a
HTML form that includes the number to square.
</p>
<form action="square/submit" method="post">
<p>
Square this <input type="number" name="x" value="{{ visits }}" />
</p>
<p>
<input type="submit" />
</p>
</form>
<script src="/autobahn.min.js"></script>
<script>
var connection = new autobahn.Connection({
url: "ws://127.0.0.1:9000",
realm: 'realm1'
});
connection.onopen = function (session) {
console.log("connected");
// subscribe to the "onvisit" topic and receive
// an event with total number of page visitors
//
session.subscribe('com.example.onvisit',
function (args, kwargs) {
console.log('Visits: ' + kwargs.visits);
// upon receiving an event, call a remote
// procedure to square the number received
// in the event
//
session.call('com.example.square', [kwargs.visits]).then(
function (res) {
console.log('square: ' + res);
}
);
}
).then(
function (sub) {
console.log("subscribed")
}
);
};
connection.open();
</script>
{% endblock %}
|