An RRA: Real RESTful API

An RRA: Real RESTful API

by Frédéric Massart ⭐ -
Number of replies: 3
Picture of Core developers Picture of Plugin developers Picture of Testers

Those who use and have used the Moodle Webservices will know that it can be rather painful. Amongst other things, the lack of use of HTTP methods (GET, POST, DELETE, ...) and the lack of HTTP status codes. Getting a "200 OK" response when a resource does not exist, or when the token is invalid is not quite right.

It has been a while since I thought I could hack something together which would define decent URLs while using the existing external API functions. And so I did! I spent the last two days playing with this. The plan was to put together a working prototype in order to assess whether my plans were realistic, and if yes, have a proof of concept to show.

Can't wait? Check out the README on Github.

Essentially, the plugin defines routes and HTTP methods which call existing external API functions. It's slightly more challenging than this, it's unfortunately not a one to one operation. Parameters need to be mapped to fit with the external API. The external API may not return the data in the format that we need. And most importantly, the HTTP status codes must be hand-picked for each operation and result in order to be useful.

I've put together some operations for courses and would love to hear your feedback.

> The repo is here <

Average of ratings: Useful (6)
In reply to Frédéric Massart ⭐

Re: An RRA: Real RESTful API

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Fred,

this look really interesting, have you thought about submitting this for core?

Do you mind if I create a MDL issue so we can discuss it?

Regards, Juan

In reply to Juan Leyva

Re: An RRA: Real RESTful API

by Frédéric Massart ⭐ -
Picture of Core developers Picture of Plugin developers Picture of Testers
Sure, I don't mind at all. You may want to consider GraphQL instead though.
Average of ratings: Useful (2)
In reply to Frédéric Massart ⭐

Re: An RRA: Real RESTful API

by HSz HSz -

Having a GraphQL to access Moodle (even if only read-only for now) would be great!