Comparison

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
parent 3802:f88e07630e4e
child 3809:a70f5a6c7f01
comparison
equal deleted inserted replaced
3807:b0449faca52b 3808:02164f8aebac
111 The payload MUST contain one (1) `message`, `presence` or `iq` stanza. 111 The payload MUST contain one (1) `message`, `presence` or `iq` stanza.
112 112
113 The stanzas MUST NOT have an `xmlns` attribute, and the default/empty 113 The stanzas MUST NOT have an `xmlns` attribute, and the default/empty
114 namespace is treated as `jabber:client`. 114 namespace is treated as `jabber:client`.
115 115
116 # Examples
117
118 ## Python / Flask
119
120 Simple echo bot that responds to messages:
121
122 ```python
123 from flask import Flask, Response, request
124 import xml.etree.ElementTree as ET
125
126 app = Flask('echobot')
127
128 @app.before_request
129 def parse():
130 request.stanza = ET.fromstring(request.data)
131
132 @app.route('/', methods = ['POST'])
133 def hello():
134 if request.stanza.tag == 'message':
135 return Response('<message><body>Yes this is bot</body></message>', content_type='application/xmpp+xml')
136
137 return Response(status = 501)
138
139 if __name__ == '__main__':
140 app.run()
141 ```
142
116 # Compatibility 143 # Compatibility
117 144
118 Requires Prosody trunk / 0.12 145 Requires Prosody trunk / 0.12