# HG changeset patch # User Kim Alvefur # Date 1577876806 -3600 # Node ID 02164f8aebac9efea5827b358191b0923e772cfb # Parent b0449faca52bd7753174bf36b8424bcfa25cff53 mod_rest: Add an example Flask thing diff -r b0449faca52b -r 02164f8aebac mod_rest/README.markdown --- 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('Yes this is bot', content_type='application/xmpp+xml') + + return Response(status = 501) + +if __name__ == '__main__': + app.run() +``` + # Compatibility Requires Prosody trunk / 0.12