diff mod_rest/README.markdown @ 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 f88e07630e4e
children a70f5a6c7f01
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