插件Web 服务

REST protocol (with JSON/XML payload support)

webservice_restjsonOwen Barritt

  • Moodle 1.9–5.1
  • 更新 2016-02-19

REST webservice protocol based on the standard core REST webservice, but with added support for JSON & XML payloads
and supports using HTTP ACCEPTS headers for determining response format.
REST webservice protocol based on the standard core REST webservice, but with added support for JSON & XML payloads and supports using HTTP ACCEPTS headers for determining response format.
Installation
Simply place the plugin files in ./webservice/restjson
Setup
Should be enabled and setup in the standard way for webservices.  See https://docs.moodle.org/29/en/Using_web_services for details.
Usage
The protocol can be called in the usual way for webservices with either JSON or XML data specified in content type (also backward compatible with current REST webservice so will also accept POST form data)
e.g. for a JSON payload
curl -H “Content-Type: application/json” -X POST -d ‘{“wsfunction”:” … “, “wstoken”:”…”, request  object }’ http://moodle.url/path/to/webservice/restjson/server.php
Parameters such as wsfunction and wstoken can also still be specified in the URL if required
curl -H “Content-Type: application/json” -X POST -d ‘{ request  object }’ http://moodle.url/path/to/webservice/restjson/server.php?wsfunction=…&wstoken= …
Response format can also be set to XML or JSON by setting the accept HTTP header e.g. to send in JSON and receive in XML (by default same format is used to return as originally received) you could use:
curl -H “Content-Type: application/json” -H “Accept: application/xml”-X POST -d ‘{ request  object }’ http://moodle.url/path/to/webservice/restjson/server.php?wsfunction=…&wstoken= …

返回插件目录