Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Web services: Difference between revisions

From MoodleDocs
(39 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{Moodle_2.0}}
=== How it works ===
 
This example will give you an idea of how our web services infrastructure works.  
==Introduction==
#The client sends a username and password to the web service login script.
This page described the Web Services module implemented for Moodle 2.0<br>
#The script returns a token for that user account.
The official discussion [http://moodle.org/mod/forum/view.php?id=6971| forum is here]<br>
#The client calls a particular web service function on a protocol server including the token .
The tracker issues are here: MDL-12886 and MDL-17135<br>
#The protocol server uses the token to check that the user can call the function.
This module is been implemented by Moodle HQ and [http://blogs.dfwikilabs.org/moodle_ws/ DFWS Team].
#The protocol server calls the matching external function, located under the \component\external namespace (previously in a externallib.php file inside the relevant module).
 
The objective is to support multiple web service protocols (REST, SOAP, XML-RPC and AMF). Adding support for a new protocol should be relatively easy.
 
== How it works ==
This following example would work but it will not be the unique way to access web services. Please have a look to the [[External services security]] page for more details.
#The client sends a username and password to the web service protocol server script.
#The protocol server returns a session token for that user account (how this is sent depends on the protocol).
#The client calls a particular web service function including the session token.
#The protocol server uses the token to check that the web service session is still active.
#The protocol server call the matching external function, located in a externallib.php file inside the relevant module.
#The external function checks that the current user has_capability to do this operation.
#The external function checks that the current user has_capability to do this operation.
#The external function calls the matching Moodle core function (in lib.php usually).
#The external function calls the matching Moodle core function (in lib.php usually).
Line 22: Line 12:
#The protocol server returns the result to the client.
#The protocol server returns the result to the client.


==Web description format==
== Developer documentation==
The full API can be found on any Moodle sites under ''' Administration block > Plugins > Web services > API Documentation'''.
 
'''Note:''' Additional services are available for uploading and downloading files which are not in the API Documentation - they are accessed in a different way. See [[Web services files handling]]


All functions that can be called via web services can be declared in a db/service.php file and can be defined in an externallib.php file somewhere. The description of the functions that can be called, and what parameters they require, are explained in the [https://docs.moodle.org/en/Development:Web_services_description External Service description document].
* [[How to contribute a web service function to core]]
* [[Adding a web service to a plugin| Adding a web service to your plugin]]
* Code example: [https://gist.github.com/timhunt/51987ad386faca61fe013904c242e9b4 Adding a web service, using APIs] by (Tim Hunt)
* [[Creating a web service client | Implement a web service client]]
* [[Web services files handling]]
* [[Web_services_Roadmap | Web service Listing & Roadmap]]


==Web services technical documentation==
== Specification and brainstorming ==
In order to facilitate a Moodle web service client implementation, every Moodle sites will provide a page listing all function descriptions. This page also gives some useful advice for any supported protocol. To call this page: ''your_moodle/webservice/wsdoc.php?protocol=soap
* [[External services security | External services security]]
''
* [[External services description | External services description]]


==Authentication==
== See also ==
Please have a look to the [[External services security]] page
* [[Web_service_API_functions|Web service API functions]]
==See also==
* [[:en:Web_services_FAQ|Web services FAQ]]
* [[External services security]]
* [[:en:How_to_create_and_enable_a_web_service|How to create and enable a web service]]
* [[External services description]]
* [[:en:Enable mobile web services|How to enable the mobile web service]]
* [[Creating_a_web_service_and_a_web_service_function]]
* [[:en:Web_services|Web services user documentation]]
* [[Web_Services]]
* [http://www.slideshare.net/juanleyva/mastering-moodle-web-services-development Mastering Moodle Web Services development] - Last session of the Hackfest in the MoodleMoot UK 2016


[[Category:Web Services]]
[[Category:Web_Services]]

Revision as of 17:47, 30 October 2020

How it works

This example will give you an idea of how our web services infrastructure works.

  1. The client sends a username and password to the web service login script.
  2. The script returns a token for that user account.
  3. The client calls a particular web service function on a protocol server including the token .
  4. The protocol server uses the token to check that the user can call the function.
  5. The protocol server calls the matching external function, located under the \component\external namespace (previously in a externallib.php file inside the relevant module).
  6. The external function checks that the current user has_capability to do this operation.
  7. The external function calls the matching Moodle core function (in lib.php usually).
  8. The core function can return a result to the external function.
  9. The external function will return a result to the protocol server.
  10. The protocol server returns the result to the client.

Developer documentation

The full API can be found on any Moodle sites under Administration block > Plugins > Web services > API Documentation.

Note: Additional services are available for uploading and downloading files which are not in the API Documentation - they are accessed in a different way. See Web services files handling

Specification and brainstorming

See also