API Driven
Development in
Moodle
Bharat Pareek
Dhawal Bargir
Mission: Improve Open Source UI & UX
Default Layout
Remui Layout
Next Challenge: Grading UX
Design Solution
By Pass: Without Changing Moodle core
Rapid
Grader
Front-end
Moodle
DB
Moodle
API
Wait, What’s an API?
Google
Maps
in Uber
Request : Start and End Location and Time
Response: Distance, Traffic, etc
When API plugin development is needed?
● Connecting to an external software
● When overriding existing feature does not give you the
required control.
Amazing Moodle API
Mobile Apps
Web Clients {....}
React
Angular
GET / POST
JSON / XML
API Gateway
API Clients
Food items
in order
Order placed
message
Current Grading Interface
Moodle
Edwiser RapidGrader Interface
Easily distinguish between
graded/non graded users
Easily navigate between questions
API Development in Moodle
External service description
Think it of like a file where we
need to register our APIs.
External functions
External functions are used to
create API endpoints
API Calls
Call the API endpoint and
process the response received.
03
01 02
Know more about it:
https://docs.moodle.org/dev/External_services_description#Service_discovery
https://docs.moodle.org/dev/External_functions_API#Overview
External Service description
Registering your API endpoint in db/services.php file of a Moodle plugin.
<?php
$functions = array(
'block_grader_get_quiz_questions' => array(
'classname' => block_graderexternalapi',
'methodname' => get_quiz_questions
)
);
External Functions
Methods which are stored in externallib.php that can be accessed by external programs like an API client.
/**
* Describes the structure of parameters for the function.
*/
public static function get_quiz_questions_parameters() {
return new external_function_parameters(
array (
'attemptid' => new external_value(PARAM_INT, 'Attempt ID.', VALUE_DEFAULT, 0),
)
);
}
/**
* Get attempt questions
**/
public static function get_quiz_questions($attemptid) {
// business logic
return $questions;
}
/**
* Describes the structure of the function return value.
*/
public static function get_quiz_questions_returns() {
new external_single_structure(
array(
'number' => new external_value(PARAM_INT, 'Question Number'),
'status' => new external_value(PARAM_RAW, 'Question Status')
)
)
}
API Endpoints
http://moodle.server/webservice/rest/server.php?wsfunction=get_quiz_questions
An API endpoint is a URL with some parameters.
&wstoken=SECURITYTOKEN;
Precautions you need to take?
Security
System monitoring
Thank you for Listening
Quiz to jog your memory http://edwiser.org/api-quiz
You win products from Edwiser
Any Questions?
Thank you!

API-Driven Development in Moodle

  • 1.
  • 2.
    Mission: Improve OpenSource UI & UX
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
    By Pass: WithoutChanging Moodle core Rapid Grader Front-end Moodle DB Moodle API
  • 8.
    Wait, What’s anAPI? Google Maps in Uber Request : Start and End Location and Time Response: Distance, Traffic, etc
  • 9.
    When API plugindevelopment is needed? ● Connecting to an external software ● When overriding existing feature does not give you the required control.
  • 10.
    Amazing Moodle API MobileApps Web Clients {....} React Angular GET / POST JSON / XML API Gateway API Clients Food items in order Order placed message
  • 11.
  • 12.
    Edwiser RapidGrader Interface Easilydistinguish between graded/non graded users Easily navigate between questions
  • 13.
    API Development inMoodle External service description Think it of like a file where we need to register our APIs. External functions External functions are used to create API endpoints API Calls Call the API endpoint and process the response received. 03 01 02 Know more about it: https://docs.moodle.org/dev/External_services_description#Service_discovery https://docs.moodle.org/dev/External_functions_API#Overview
  • 14.
    External Service description Registeringyour API endpoint in db/services.php file of a Moodle plugin. <?php $functions = array( 'block_grader_get_quiz_questions' => array( 'classname' => block_graderexternalapi', 'methodname' => get_quiz_questions ) );
  • 15.
    External Functions Methods whichare stored in externallib.php that can be accessed by external programs like an API client. /** * Describes the structure of parameters for the function. */ public static function get_quiz_questions_parameters() { return new external_function_parameters( array ( 'attemptid' => new external_value(PARAM_INT, 'Attempt ID.', VALUE_DEFAULT, 0), ) ); } /** * Get attempt questions **/ public static function get_quiz_questions($attemptid) { // business logic return $questions; } /** * Describes the structure of the function return value. */ public static function get_quiz_questions_returns() { new external_single_structure( array( 'number' => new external_value(PARAM_INT, 'Question Number'), 'status' => new external_value(PARAM_RAW, 'Question Status') ) ) }
  • 16.
  • 17.
    Precautions you needto take? Security System monitoring
  • 18.
    Thank you forListening Quiz to jog your memory http://edwiser.org/api-quiz You win products from Edwiser
  • 19.
  • 20.