1782
|
1 #summary HTTP access to prosody’s storage mechanism |
|
2 |
|
3 = Introduction = |
|
4 |
|
5 This module gives HTTP access to prosody’s storage mechanism. It uses normal HTTP verbs and [http://tools.ietf.org/html/rfc2617 Basic HTTP authentication], so you could call it RESTful if you like buzzwords. |
|
6 |
|
7 = Syntax = |
|
8 |
|
9 To Fetch data, issue a normal GET request |
|
10 {{{ |
|
11 GET /data[/<host>/<user>]/<store>[/<format>] HTTP/1.1 |
|
12 Authorization: <base64(authzid:password)> |
|
13 |
|
14 -- OR -- |
|
15 |
|
16 PUT|POST /data[/<host>/<user>]/<store> HTTP/1.1 |
|
17 Content-Type: text/x-lua | application/json |
|
18 |
|
19 <data> |
|
20 }}} |
|
21 |
|
22 These map to `datamanager.method(user, host, store, data)`, where choice of `method` and its parameters are explained below. |
|
23 |
|
24 == Verbs == |
|
25 |
|
26 ||*Verb*||*Meaning* ||*datamanager method* || |
|
27 ||`GET` || Just fetch data || `load()` or `list_load()` || |
|
28 ||`PUT` || Replace all data in the store || `store() || |
|
29 ||`POST`|| Append item to the store || `list_append()` || |
|
30 |
|
31 Note: In a `GET` request, if `load()` returns `nil`, `list_load()` will be tried instead. |
|
32 |
|
33 == Fields == |
|
34 |
|
35 ||*Field*||*Description*||*Default*|| |
|
36 ||`host`||Which virtual host to access||Required. If not set in the path, the domain-part of the authzid is used.|| |
|
37 ||`user`||Which users storage to access||Required. If not set in the path, uses the node part of the authzid.|| |
|
38 ||`store`||Which storage to access.||Required.|| |
|
39 ||`format`||Which format to serialize to. `json` and `lua` are supported. When uploading data, the `Content-Type` header is used.||`json`|| |
|
40 ||`data`||The actual data to upload in a `PUT` or `POST` request.||`nil`|| |
|
41 |
|
42 Note: Only admins can change data for users other than themselves. |
|
43 |
|
44 == Example usage == |
|
45 |
|
46 Here follows some example usage using `curl`. |
|
47 |
|
48 Get your account details: |
|
49 |
|
50 {{{ |
|
51 curl http://prosody.local:5280/data/accounts -u user@example.com:secr1t |
|
52 {"password":"secr1t"} |
|
53 }}} |
|
54 |
|
55 Set someones account details: |
|
56 |
|
57 {{{ |
|
58 curl -X PUT http://prosody.local:5280/data/example.com/user/accounts -u admin@host:r00tp4ssw0rd --header 'Content-Type: application/json' --data-binary '{"password":"changeme"}' |
|
59 }}} |
|
60 |
|
61 == Client library == |
|
62 |
|
63 * https://metacpan.org/module/Prosody::Mod::Data::Access |
|
64 |
|
65 == TODO == |
|
66 |
|
67 * Use `Accept` header. |