REST-based Moodle Web Services

REST-based Moodle Web Services

by Mark Roggenkamp -
Number of replies: 7
All,

I've begun creating a simple REST-based web services API for Moodle. I'm posting the code here for comments and suggestions. Within the next few months we will be changing around out integration with Moodle to use this API.

Currently, only categories are exposed. However, now that I have one done, most of the code will carry through for the others like users, courses, enrollments, etc.

The service sends back XHTML in the form of the Microformat XOXO. I'm not sure that this is the best symantic representation of this data but I'm going with it until I find a good reason not to. Since the return format is a simple PHP based template I can change this pretty easily.

Authentication is communicated via HTTP Basic Auth. The authentication credentials are verified with the Moodle DB (after MD5'ing the password). The user provided must be an admin in Moodle. Based on feedback I'll probably change the authorization to something more useful but it works for me so far. The authentication and authorization is easy to switch out if need be. Since the credentials are being passed in cleartext a production environment exposing these services should also have SSL available as well.

I've also written a simple python client that I've been using to test and troubleshoot. There is a python module for each CRUD operation (Create, Read, Update, Delete). Each python module can be called from the command-line. When called with no arguments the usage information is displayed.

My latest code is attached. If anyone else is interested I will continue to post updated code as it's completed.

Best Regards,
Mark Roggenkamp
mark.roggenkamp@gmail.com

Average of ratings: -
In reply to Mark Roggenkamp

Re: REST-based Moodle Web Services

by Mark Roggenkamp -
I neglected to mention one important thing. The moodle-ws-0.1 folder needs to be placed withing /moodle/lib/ (assuming the name of your moodle instance is moodle). I named my moodle-ws-0.1 folder ws, so it's located at /moodle/lib/ws. Under the ws folder is a categories folder.

Cheers,
Mark
In reply to Mark Roggenkamp

Re: REST-based Moodle Web Services

by Mark Roggenkamp -
I've release new code with the following changes:

1. The client now supports ssl. Just pass an https:// based URL.
2. I've added a README to both the client and server along with an INSTALL doc for the server piece.
3. I've added an index in the root of the root so that I can use slash args and look for collections to expose by looking for ws folders within modules in the mod folder. For instance /moodle/lib/ws/index.php/lesson/35 could return a listing of all lessons in course id 35 if the author of lesson chose to expose it that way.

The code is posted at: http://www.lentric.com/code/

I'll keep plugging away. Please send and comments or questions my way.

Cheers,
Mark

In reply to Mark Roggenkamp

Svar: REST-based Moodle Web Services

by Anders Berggren -
Hi Mark,
Unfortunately I am not a developer/programmer
so I don't quite understand what this is. Maybe
a stupid question clown - but does this mean that
other applications will be able to use/import
Moodle activities (like e.g. a forum) as Web
Services? So that Moodle can can communicate
with e.g. other Learning Design standard compliant
applications via your API - and maybe vice versa?
That would be very exciting!
Cheers, Anders
In reply to Anders Berggren

Re: Svar: REST-based Moodle Web Services

by Mark Roggenkamp -
Anders,

The answer is, sorta. smile

This provides the infrastructure for something like the forum to expose it's data to other systems. However, some code will need to be written specifically for the forum. Currently, I'm exposing the categories and I'm working on users next. Once I get categories, users, courses and enrollments exposed I'll look at others.

Of course anything that wants to talk to this service would need to now how to talk to a REST-based service. In short, REST-based means that all resources that your are exposing have a specific URL (ie. http://www.mymoodle.com/moodle/lib/ws/index.php/categories/49 sends back information about the category with the id 49). It also means that these resources can be manipulated via standard HTTP verbs (GET, POST, PUT, DELETE). Typically a browser uses GET to get a webpage from a webserver and POST to send data to the webserver. PUT and DELETE have been around in the HTTP spec for a long time but just haven't been used very often until lately.

Apart from the communications over HTTP, this service sends data back to the client as a microformat known as XOXO. Microformats are simply HTML (XHTML really) with certain attributes and nested certain ways. I could fairly easily send back the data as ATOM (aka the new and improved RSS). If make a few minor modifications (which I may do at some point) this could turn into and APP (Atom Publishing Protocol) based service which would enable many newer Blog clients to get at moodle data.

The client I've written is in Python but I may at some point write a client in Java or something else to encourage companies to use the api to integration with Moodle. If necessary and PHP client could easily be written as well using the CURL library.

Also, just to be clear this is a server and exposes Moodle data, it does not call out to any other server. I believe there is already work being done along those lines for a specific integration with a vendor.

That's probably more than you wanted but maybe sombody will be interested in all that detail. smile

Thank you for your interest,

Mark
In reply to Mark Roggenkamp

Re: Svar: REST-based Moodle Web Services

by Dwight Ian -
Good Day,

Hi, I've been looking around for something like this and I was relieved that this exists.

Im new at webservices, my question is, how do you call the webservice? Like if I have an application say written in another php applicatio, how will i call the service (do i use file() or fopen()?)

then how will i also do a POST to a RESTful API?

thanks.

More Power!
In reply to Mark Roggenkamp

Re: REST-based Moodle Web Services

by carlos cepeda -

Greeting
Hello am I a student of system engineering and I am employed at something related to web services on moodle, my question is at present the version 2 of moodle it works with rest??, in the code source is there an api of restful, if it is used, that services use her??

In reply to carlos cepeda

Re: REST-based Moodle Web Services

by snadly Mohamed Amine -

hi I need to use these rest web services in the communication between  android  and moodle 2.0 ! is that possible?