General developer forum

An RRA: Real RESTful API

 
Picture of Frédéric Massart
An RRA: Real RESTful API
 

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)
Picture of Juan Leyva
Re: An RRA: Real RESTful API
Core developersMoodle HQParticularly helpful MoodlersPlugin developersTesters

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

 
Average of ratings: -
Picture of Frédéric Massart
Re: An RRA: Real RESTful API
 
Sure, I don't mind at all. You may want to consider GraphQL instead though.
 
Average of ratings: Useful (2)
Picture of HSz HSz
Re: An RRA: Real RESTful API
 

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

 
Average of ratings: -