nitlight_aas: offer a low-level JSON service
[nit.git] / src / examples / nitlight_as_a_service.nit
index 934bded..103a3c8 100644 (file)
@@ -22,6 +22,7 @@ import highlight
 import nitcorn
 import nitcorn::log
 import template
+import json::serialization_write
 
 # Nitcorn service to hightlight code
 #
@@ -39,6 +40,13 @@ class HighlightAction
                var hlcode = null
                if code != null then hlcode = hightlightcode(hl, code)
 
+               if http_request.post_args.get_or_null("json") == "true" and hlcode != null then
+                       var response = new HttpResponse(200)
+                       response.header["Content-Type"] = "text/json"
+                       response.body = hlcode.to_json
+                       return response
+               end
+
                if http_request.post_args.get_or_null("ajax") == "true" and hlcode != null then
                        page.add hlcode.code_mirror_update
                        page.add """