changeset 3808:02164f8aebac

mod_rest: Add an example Flask thing
author Kim Alvefur <zash@zash.se>
date Wed, 01 Jan 2020 12:06:46 +0100
parents b0449faca52b
children a70f5a6c7f01
files mod_rest/README.markdown
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_rest/README.markdown	Wed Jan 01 10:59:24 2020 +0100
+++ b/mod_rest/README.markdown	Wed Jan 01 12:06:46 2020 +0100
@@ -113,6 +113,33 @@
 The stanzas MUST NOT have an `xmlns` attribute, and the default/empty
 namespace is treated as `jabber:client`.
 
+# Examples
+
+## Python / Flask
+
+Simple echo bot that responds to messages:
+
+```python
+from flask import Flask, Response, request
+import xml.etree.ElementTree as ET
+
+app = Flask('echobot')
+
+@app.before_request
+def parse():
+    request.stanza = ET.fromstring(request.data)
+
+@app.route('/', methods = ['POST'])
+def hello():
+    if request.stanza.tag == 'message':
+        return Response('<message><body>Yes this is bot</body></message>', content_type='application/xmpp+xml')
+
+    return Response(status = 501)
+
+if __name__ == '__main__':
+    app.run()
+```
+
 # Compatibility
 
 Requires Prosody trunk / 0.12