--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014-2015 Alexandre Terrasa <alexandre@moz-code.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import popcorn
+
+class CounterAPI
+ super Handler
+
+ var counter = 0
+
+ fun json_counter: JsonObject do
+ var json = new JsonObject
+ json["label"] = "Visitors"
+ json["value"] = counter
+ return json
+ end
+
+ redef fun get(req, res) do
+ res.json(json_counter)
+ end
+
+ redef fun post(req, res) do
+ counter += 1
+ res.json(json_counter)
+ end
+end
+
+var app = new App
+app.use("/counter", new CounterAPI)
+app.use("/*", new StaticHandler("www/"))
+app.listen("localhost", 3000)
--- /dev/null
+<!DOCTYPE html>
+<html lang='en' ng-app='ng-example'>
+ <head>
+ <base href='/'>
+ <title>ng-example</title>
+ </head>
+ <body>
+ <div ng-view></div>
+
+ <script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.min.js'></script>
+ <script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular-route.js'></script>
+ <script src='/javascripts/ng-example.js'></script>
+ </body>
+</html>
--- /dev/null
+/*
+ * Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+(function() {
+ angular
+
+ .module('ng-example', ['ngRoute'])
+
+ .factory('CounterModel', ['$http', function($http) {
+ return {
+ load: function(cb, cbErr) {
+ $http.get('/counter')
+ .success(cb)
+ .error(cbErr);
+ },
+ increment: function(cb, cbErr) {
+ $http.post('/counter')
+ .success(cb)
+ .error(cbErr);
+ }
+ };
+ }])
+
+ .controller('CounterCtrl', ['CounterModel', function(CounterModel) {
+ var $this = this;
+
+ this.loadCounter = function() {
+ CounterModel.load(
+ function(data) {
+ $this.counter = data;
+ }, function(err) {
+ $this.error = err;
+ });
+ };
+
+ this.incrementCounter = function() {
+ CounterModel.increment(
+ function(data) {
+ $this.counter = data;
+ }, function(err) {
+ $this.error = err;
+ });
+ };
+
+ this.loadCounter();
+ }])
+
+ .config(function($routeProvider, $locationProvider) {
+ $routeProvider
+ .when('/', {
+ templateUrl: 'views/index.html',
+ controller: 'CounterCtrl',
+ controllerAs: 'counterCtrl'
+ })
+ .otherwise({
+ redirectTo: '/'
+ });
+ $locationProvider.html5Mode(true);
+ });
+})();
--- /dev/null
+<h1>Nit ♥ Angular.JS</h1>
+
+<p>Click the button to increment the counter.</p>
+
+<form>
+ <label>{{counterCtrl.counter.label}}</label>
+ <input type="number" ng-model="counterCtrl.counter.value" readonly />
+ <button ng-click="counterCtrl.incrementCounter()">Increment!</button>
+</form>
--- /dev/null
+
+[Client] curl -s localhost:*****/counter
+{"label":"Visitors","value":0}
+[Client] curl -s localhost:*****/counter -X POST
+{"label":"Visitors","value":1}
+[Client] curl -s localhost:*****/counter
+{"label":"Visitors","value":1}
\ No newline at end of file
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import example_angular
+import base_tests
+
+class TestClient
+ super ClientThread
+
+ redef fun main do
+ system "curl -s {host}:{port}/counter"
+ system "curl -s {host}:{port}/counter -X POST"
+ system "curl -s {host}:{port}/counter"
+ return null
+ end
+end
+
+var app = new App
+app.use("/counter", new CounterAPI)
+app.use("/*", new StaticHandler("www/"))
+
+var host = test_host
+var port = test_port
+
+var server = new AppThread(host, port, app)
+server.start
+0.1.sleep
+
+var client = new TestClient(host, port)
+client.start
+client.join
+0.1.sleep
+
+exit 0