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
Line 7: Line 7:


=Implementation=
=Implementation=
Web Services module has been conceived in a purpose to be ported on different Moodle version, and also on different project. It has also for purpose to support multiple web service protocols (REST, SOAP, AMFPHP, ...). Adding a new protocol support should be relatively easy.
Web Services module has been conceived in a purpose to be ported on different Moodle version, and also on different project. It has also for purpose to support multiple web service protocols (REST, SOAP, AMF, ...). Adding a new protocol support should be relatively easy.


== How does it work ==
== How does it work ==
The web service client call a Moodle web service. The web service is located in a folder specific to the used protocol. It's usually a inout.php file. This file runs the web service server and gets the sent parameters. Then it calls a wrapper. The wrapper.php file is implemented in order to call the Moodle API which contains all callable functions. The wrapper will check a "generated file" in order to know which functions are available, and what their parameters and what they returned.<br>
#The client requests a token from the web services server. For that the client sends a username/password.
For any protocol there should be at least one inout.php file and one wrapper file.
#The web service server generates a token for this username and send it back to the client
 
#The client calls a web service (module name, function name, and function parameters) and joins the token to it
 
#The web service server authenticate the token, then call the matching web service function. The web service function is located in a external.php file. This external.php file contains all web service functions of for a module. The external.php file is located into the module folder.
== Technical specs ==
#The web service function check capability, and call Moodle core function.
# The client calls the web service
#The core function can return a result to the web service function. The web service can also return the result to the server. The server return the result to the client
# The web service server receives the call
# The web service server transforms the web service params into a common param format to all web service protocol => Format to be defined
# The web service server calls a function call_moodle_function($functionname, $params)
# call_moodle_function() checks through a WS API descriptor class that the params are legal for this function name
# call_moodle_function() call the correct API moodle function
# the call_moodle_function() return the result to the web service server
# the web service server convert the result into a response
 
Params should include:
* function parameter names, values and types
* returned object fields (e.g. we cannot return a password field through a get_users function)
* return value and type


=Security=
=Security=

Revision as of 06:11, 23 January 2009

Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please join the discussion on moodle.org or use the page comments.

Moodle 2.0


Introduction

This page described the Web Services module implemented for Moodle 2.0
The tracker issue is here: MDL-12886
This module is been implemented by the DFWS Team and Moodle.

Implementation

Web Services module has been conceived in a purpose to be ported on different Moodle version, and also on different project. It has also for purpose to support multiple web service protocols (REST, SOAP, AMF, ...). Adding a new protocol support should be relatively easy.

How does it work

  1. The client requests a token from the web services server. For that the client sends a username/password.
  2. The web service server generates a token for this username and send it back to the client
  3. The client calls a web service (module name, function name, and function parameters) and joins the token to it
  4. The web service server authenticate the token, then call the matching web service function. The web service function is located in a external.php file. This external.php file contains all web service functions of for a module. The external.php file is located into the module folder.
  5. The web service function check capability, and call Moodle core function.
  6. The core function can return a result to the web service function. The web service can also return the result to the server. The server return the result to the client

Security

How are the web services secured ?
Security layer implemented by every protocol?

List of functions

All callable functions are declared into Moodle API, please read Moodle API documentation.