diff options
author | Andreas Gohr <andi@splitbrain.org> | 2023-04-27 08:15:37 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2023-04-27 08:15:37 +0200 |
commit | f657e5d050d6b1d1cb1ea1c656f5aec61f5067de (patch) | |
tree | 3748a9da0d63a109b9042bc28d3a209fcd5acd23 /lib/exe/jsonrpc.php | |
parent | 605810ee2fba6c1a323e320dde2c78747b3e5f3a (diff) | |
download | dokuwiki-f657e5d050d6b1d1cb1ea1c656f5aec61f5067de.tar.gz dokuwiki-f657e5d050d6b1d1cb1ea1c656f5aec61f5067de.zip |
Add JSON based alternative to XMLRPC
XMLRPC is a rather outdated and old-fashioned protocol not much in use
anymore. Developers prefer simpler, JSON based APIs.
This adds a new "JSONRPC" API. Basically it exposes exactly the same
method calls as the XMLRPC API but using JSON instead of XML. It's not a
classical REST API, but should be just as easy to use for developers.
Here is an example call using CURL:
curl http://localhost/dokuwiki/lib/exe/jsonrpc.phs \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $token" \
-d '["wiki"]'
Please note that the above uses the token auth implemented in #2432.
Authentication via basic auth or cookies would work as well.
Diffstat (limited to 'lib/exe/jsonrpc.php')
-rw-r--r-- | lib/exe/jsonrpc.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/exe/jsonrpc.php b/lib/exe/jsonrpc.php new file mode 100644 index 000000000..3852e2b45 --- /dev/null +++ b/lib/exe/jsonrpc.php @@ -0,0 +1,31 @@ +<?php + +use dokuwiki\Remote\JsonRpcServer; + +if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../'); + +require_once(DOKU_INC . 'inc/init.php'); +session_write_close(); //close session + +header('Content-Type: application/json'); + +$server = new JsonRpcServer(); +try { + $result = [ + 'error' => [ + 'code' => 0, + 'message' => 'success' + ], + 'data' => $server->serve(), + ]; +} catch (\Exception $e) { + $result = [ + 'error' => [ + 'code' => $e->getCode(), + 'message' => $e->getMessage() + ], + 'data' => null, + ]; +} + +echo json_encode($result); |