Software /
code /
prosody-modules
Comparison
mod_pubsub_post/README.markdown @ 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 |
parent | 4636:6bcccc63b542 |
child | 4961:18774cc621d6 |
comparison
equal
deleted
inserted
replaced
4841:f69c5a443156 | 4842:8d4b91a703af |
---|---|
104 local pubsub = mod_pubsub.service; | 104 local pubsub = mod_pubsub.service; |
105 | 105 |
106 pubsub:create("princely_musings", true); | 106 pubsub:create("princely_musings", true); |
107 pubsub:set_affiliation("princely_musings", true, "127.0.0.1", "publisher"); | 107 pubsub:set_affiliation("princely_musings", true, "127.0.0.1", "publisher"); |
108 ``` | 108 ``` |
109 | |
110 ## Data mappings | |
111 | |
112 The datamapper library added in trunk allows posting JSON and having it | |
113 converted to XML based on a special JSON Schema. | |
114 | |
115 ``` json | |
116 { | |
117 "properties" : { | |
118 "content" : { | |
119 "type" : "string" | |
120 }, | |
121 "title" : { | |
122 "type" : "string" | |
123 } | |
124 }, | |
125 "type" : "object", | |
126 "xml" : { | |
127 "name" : "musings", | |
128 "namespace" : "urn:example:princely" | |
129 } | |
130 } | |
131 ``` | |
132 | |
133 And in the Prosody config file: | |
134 | |
135 ``` lua | |
136 pubsub_post_mappings = { | |
137 princely_musings = "musings.json"; | |
138 } | |
139 ``` | |
140 | |
141 Then, POSTing a JSON payload like | |
142 | |
143 ``` json | |
144 { | |
145 "content" : "To be, or not to be: that is the question", | |
146 "title" : "Soliloquy" | |
147 } | |
148 ``` | |
149 | |
150 results in a payload like | |
151 | |
152 ``` xml | |
153 <musings xmlns="urn:example:princely"> | |
154 <title>Soliloquy</title> | |
155 <content>To be, or not to be: that is the question</content> | |
156 </musings> | |
157 ``` | |
158 | |
159 being published to the node. |