When the API You Need Does Not Exist
May, 08 2014. 6 minutes read.
This post is about what to do when the tool you depend on is missing the exact feature you need.
The Wall
I was building a tool that could create Moodle learning content from the outside, through Moodle's REST API. This matters for Indonesia, where slow internet makes it painful to author content directly in Moodle. My tool let lecturers write content offline, then push it to Moodle when a connection was available.
It worked for creating courses. But then I hit a wall. In Moodle, content lives inside "sections." And Moodle had no REST function call to create a section. The Moodle developers had proposed one, but never implemented it. The exact API I needed did not exist.
Two Options
When an API is missing, you have two choices. Give up and wait for someone else to build it. Or build it yourself.
I chose to build it. Moodle is open source and supports plugins. So I wrote two plugins. The first, "xlmsmemod," creates learning activities by writing directly to the Moodle database. The second, "xlmsmemodws," exposes that first plugin as a brand new REST function call: "xlmsmemod_create_activity." Now my external tool could call an API that Moodle itself never provided.
The Rabbit Hole
Reverse-engineering Moodle's database was not fun. To make one learning activity appear correctly, you need to insert records across multiple tables: the course table, the sections table, the modules table, and more. Miss one, and the content silently fails to show up. Moodle's documentation on these relationships was outdated. I spent a lot of time inserting records manually, watching what worked and what did not.
I also lost hours to one absurd bug: naming a plugin with a dash character ("-") makes Moodle silently refuse to detect it. Nowhere in the documentation. Just a quiet failure. These are the undocumented traps that eat researcher time.
Why It Mattered
This was early, unglamorous work. Work in progress, as the paper honestly called it. But it was a step toward a bigger goal: making Moodle usable in a country where the internet cannot be taken for granted. Sometimes progress is not a breakthrough. It is just refusing to accept "the API does not exist" as a final answer.
Read the Full Paper
Published at IEEE EDUCON 2014, Istanbul. Part of my doctoral research at Kumamoto University.
When the API you need does not exist, build it. Open source means the wall is never final.
@hepidad