Changeset

4842:8d4b91a703af

mod_pubsub_post: Document JSON to XML mapping capability
author Kim Alvefur <zash@zash.se>
date Wed, 29 Dec 2021 23:12:43 +0100
parents 4841:f69c5a443156
children 4843:60887967b797
files mod_pubsub_post/README.markdown
diffstat 1 files changed, 51 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_pubsub_post/README.markdown	Wed Dec 29 19:40:28 2021 +0100
+++ b/mod_pubsub_post/README.markdown	Wed Dec 29 23:12:43 2021 +0100
@@ -106,3 +106,54 @@
 pubsub:create("princely_musings", true);
 pubsub:set_affiliation("princely_musings", true, "127.0.0.1", "publisher");
 ```
+
+## Data mappings
+
+The datamapper library added in trunk allows posting JSON and having it
+converted to XML based on a special JSON Schema.
+
+``` json
+{
+   "properties" : {
+      "content" : {
+         "type" : "string"
+      },
+      "title" : {
+         "type" : "string"
+      }
+   },
+   "type" : "object",
+   "xml" : {
+      "name" : "musings",
+      "namespace" : "urn:example:princely"
+   }
+}
+```
+
+And in the Prosody config file:
+
+``` lua
+pubsub_post_mappings = {
+    princely_musings = "musings.json";
+}
+```
+
+Then, POSTing a JSON payload like
+
+``` json
+{
+   "content" : "To be, or not to be: that is the question",
+   "title" : "Soliloquy"
+}
+```
+
+results in a payload like
+
+``` xml
+<musings xmlns="urn:example:princely">
+  <title>Soliloquy</title>
+  <content>To be, or not to be: that is the question</content>
+</musings>
+```
+
+being published to the node.