Software / code / prosody-modules
Annotate
mod_rest/example/app.py @ 6297:502963b86fbc
:multble modules: fix tab-> space
diff --git a/mod_admin_blocklist/README.md b/mod_admin_blocklist/README.md
--- a/mod_admin_blocklist/README.md
+++ b/mod_admin_blocklist/README.md
@@ -24,9 +24,9 @@ admin_blocklist_roles = { "prosody:opera
# Compatibility
Prosody-Version Status
- -------------- ------
- trunk* Works
- 13 Works
- 0.12 Works
+ ------------ ------
+ trunk* Works
+ 13 Works
+ 0.12 Works
*as of 2025-06-13
diff --git a/mod_csi_grace_period/README.md b/mod_csi_grace_period/README.md
--- a/mod_csi_grace_period/README.md
+++ b/mod_csi_grace_period/README.md
@@ -16,9 +16,9 @@ pocket is not the best use of radio time
Works with [mod_csi_simple][doc:modules:mod_csi_simple] which is
included with Prosody.
- ------- -------
- trunk* Works
- 13 Works
- 0.12 Works
+ ------- -------
+ trunk* Works
+ 13 Works
+ 0.12 Works
*as of 2025-06-13
diff --git a/mod_http_upload_external/README.md b/mod_http_upload_external/README.md
--- a/mod_http_upload_external/README.md
+++ b/mod_http_upload_external/README.md
@@ -87,10 +87,10 @@ Compatibility
=============
Prosody-Version Status
- ---------------- --------------------
- trunk Works as of 25-06-13
- 13 Works
- 0.12 Works
+ ---------------- --------------------
+ trunk Works as of 25-06-13
+ 13 Works
+ 0.12 Works
Implementation
==============
diff --git a/mod_muc_moderation/README.md b/mod_muc_moderation/README.md
--- a/mod_muc_moderation/README.md
+++ b/mod_muc_moderation/README.md
@@ -27,11 +27,10 @@ modules_enabled = {
# Compatibility
- ------- ---------------
- trunk Works^[as of 2025-06-13]
- 13 Works
- 0.12 Works
- ------- ---------------
+ ------- ---------------
+ trunk Works^[as of 2025-06-13]
+ 13 Works
+ 0.12 Works
## XEP version
diff --git a/mod_s2s_idle_timeout/README.md b/mod_s2s_idle_timeout/README.md
--- a/mod_s2s_idle_timeout/README.md
+++ b/mod_s2s_idle_timeout/README.md
@@ -25,10 +25,9 @@ Compatibility
=============
Prosody Version Status
- ----------------- -----------
- trunk[^1] Works
- 13 Works
- 0.12 Works
- ----------------- -----------
+ ----------------- -----------
+ trunk[^1] Works
+ 13 Works
+ 0.12 Works
[^1]: as of 2025-06-13
diff --git a/mod_s2s_keepalive/README.md b/mod_s2s_keepalive/README.md
--- a/mod_s2s_keepalive/README.md
+++ b/mod_s2s_keepalive/README.md
@@ -34,10 +34,9 @@ Compatibility
=============
Prosody Version Status
- ----------------- -----------
- trunk[^1] Works
- 13 Works
- 0.12 Works
- ----------------- -----------
+ ----------------- -----------
+ trunk[^1] Works
+ 13 Works
+ 0.12 Works
[^1]: as of 2025-06-13
| author | Menel <menel@snikket.de> |
|---|---|
| date | Fri, 13 Jun 2025 09:58:51 +0200 |
| parent | 4248:f3fbfde9683d |
| rev | line source |
|---|---|
| 3853 | 1 from flask import Flask, Response, request, jsonify |
| 2 | |
| 3 app = Flask("echobot") | |
| 4 | |
| 5 | |
|
3861
ede3d1724dd1
mod_rest: Attempt to auto-discover data type wanted by callback
Kim Alvefur <zash@zash.se>
parents:
3854
diff
changeset
|
6 @app.route("/api", methods=["OPTIONS"]) |
|
ede3d1724dd1
mod_rest: Attempt to auto-discover data type wanted by callback
Kim Alvefur <zash@zash.se>
parents:
3854
diff
changeset
|
7 def options(): |
|
3863
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
8 """ |
|
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
9 Startup check. Return an appropriate Accept header to confirm the |
|
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
10 data type to use. |
|
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
11 """ |
|
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
12 |
|
3861
ede3d1724dd1
mod_rest: Attempt to auto-discover data type wanted by callback
Kim Alvefur <zash@zash.se>
parents:
3854
diff
changeset
|
13 return Response(status=200, headers={"accept": "application/json"}) |
|
ede3d1724dd1
mod_rest: Attempt to auto-discover data type wanted by callback
Kim Alvefur <zash@zash.se>
parents:
3854
diff
changeset
|
14 |
|
ede3d1724dd1
mod_rest: Attempt to auto-discover data type wanted by callback
Kim Alvefur <zash@zash.se>
parents:
3854
diff
changeset
|
15 |
| 3853 | 16 @app.route("/api", methods=["POST"]) |
| 17 def hello(): | |
|
3863
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
18 """ |
|
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
19 Example RESTful JSON format stanza handler. |
|
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
20 """ |
|
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
21 |
| 3853 | 22 print(request.data) |
| 23 if request.is_json: | |
| 24 data = request.get_json() | |
| 25 | |
| 26 if "kind" not in data: | |
| 27 return Response(status=400) | |
| 28 | |
| 29 if data["kind"] == "message" and "body" in data: | |
|
3863
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
30 # Reply to a message |
| 3853 | 31 return jsonify({"body": "Yes this is flask app"}) |
| 32 | |
| 33 elif data["kind"] == "iq" and data["type"] == "get": | |
|
4248
f3fbfde9683d
mod_rest/example: Reorder things to match the disco#info feature order
Kim Alvefur <zash@zash.se>
parents:
4246
diff
changeset
|
34 if "disco" in data: |
|
3863
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
35 # Return supported features |
| 3853 | 36 return jsonify( |
| 37 { | |
| 38 "disco": { | |
| 39 "identities": [ | |
| 40 { | |
| 41 "category": "component", | |
| 42 "type": "generic", | |
| 43 "name": "Flask app", | |
| 44 } | |
| 45 ], | |
| 46 "features": [ | |
| 47 "http://jabber.org/protocol/disco#info", | |
| 48 "http://jabber.org/protocol/disco#items", | |
|
4246
53ae1df31950
mod_rest/example: Advertise version query support
Kim Alvefur <zash@zash.se>
parents:
3863
diff
changeset
|
49 "jabber:iq:version", |
| 3853 | 50 "urn:xmpp:ping", |
| 51 ], | |
| 52 } | |
| 53 } | |
| 54 ) | |
| 55 | |
| 56 elif "items" in data: | |
|
3863
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
57 # Disco items |
| 3853 | 58 return jsonify( |
| 59 {"items": [{"jid": "example.org", "name": "Example Dot Org"}]} | |
| 60 ) | |
| 61 | |
|
3854
25c34c9f755c
mod_rest: Add mapping of XEP-0092: Software Version
Kim Alvefur <zash@zash.se>
parents:
3853
diff
changeset
|
62 elif "version" in data: |
|
3863
45b04f05d624
mod_rest: Add some comments to example code
Kim Alvefur <zash@zash.se>
parents:
3861
diff
changeset
|
63 # Version info |
|
3854
25c34c9f755c
mod_rest: Add mapping of XEP-0092: Software Version
Kim Alvefur <zash@zash.se>
parents:
3853
diff
changeset
|
64 return jsonify({"version": {"name": "app.py", "version": "0"}}) |
|
25c34c9f755c
mod_rest: Add mapping of XEP-0092: Software Version
Kim Alvefur <zash@zash.se>
parents:
3853
diff
changeset
|
65 |
|
4248
f3fbfde9683d
mod_rest/example: Reorder things to match the disco#info feature order
Kim Alvefur <zash@zash.se>
parents:
4246
diff
changeset
|
66 elif "ping" in data: |
|
f3fbfde9683d
mod_rest/example: Reorder things to match the disco#info feature order
Kim Alvefur <zash@zash.se>
parents:
4246
diff
changeset
|
67 # Respond to ping |
|
f3fbfde9683d
mod_rest/example: Reorder things to match the disco#info feature order
Kim Alvefur <zash@zash.se>
parents:
4246
diff
changeset
|
68 return Response(status=204) |
|
f3fbfde9683d
mod_rest/example: Reorder things to match the disco#info feature order
Kim Alvefur <zash@zash.se>
parents:
4246
diff
changeset
|
69 |
| 3853 | 70 return Response(status=501) |
| 71 | |
| 72 | |
| 73 if __name__ == "__main__": | |
| 74 app.run() |