# HG changeset patch # User nicoco # Date 1741787650 -3600 # Node ID 119c0eb65bf3db40efed3f58b1afa27a63b0627c # Parent 131b8bfbefb421c69c2c5d3708475a27b559a02b mod_pubsub: new module to fetch pubsub items via HTTP GET diff -r 131b8bfbefb4 -r 119c0eb65bf3 mod_pubsub_get/README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_pubsub_get/README.md Wed Mar 12 14:54:10 2025 +0100 @@ -0,0 +1,36 @@ +--- +labels: + - "Stage-Alpha" +summary: Get pubsub items via HTTP GET +--- + +# Introduction + +WARNING: this module does not implement any type of access control and will effectively make all +pubsub data public on the component it is loaded onto. + +This module lets you fetch the items of a specific pubsub node via an HTTP GET request. +I implemented it for a read-only view of comments published according to XEP-0277. + +# Configuration + +Nothing is configurable, just load the module on a specific component. + +```lua +Component "comments.example.com" "pubsub" + modules_enabled = { "pubsub_get" } +``` + +# Use + +To query the items of the node "urn:xmpp:microblog:0:comments/some-article", issue a GET for +`https://comments.example.com:5281/pubsub_get?node=urn:xmpp:microblog:0:comments/some-article`. +This will return a JSON object containing the items data. + +# TODO + +- Only return items with "open" access model + +# Compatibility + +Requires Prosody trunk / 0.12 diff -r 131b8bfbefb4 -r 119c0eb65bf3 mod_pubsub_get/mod_pubsub_get.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_pubsub_get/mod_pubsub_get.lua Wed Mar 12 14:54:10 2025 +0100 @@ -0,0 +1,19 @@ +module:depends("http") +local pubsub_service = module:depends("pubsub").service +local json = require "util.json" + +function handle_GET(event) + local request, response = event.request, event.response + local query = request.url.query + + if query:sub(1, 5) ~= "node=" then return 400 end + + local node = query:sub(6) + local ok, items = pubsub_service:get_items(node, true) + + if not ok then return 404 end + response.status_code = 200 + return json.encode(items) +end + +module:provides("http", {route = {GET = handle_GET}})