PHPackages                             udir-moodle/webservice\_restful - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. udir-moodle/webservice\_restful

ActiveMoodle-webservice[API Development](/categories/api)

udir-moodle/webservice\_restful
===============================

A REStful webservice plugin for Moodle LMS, this plugin allows Moodle's webservice interface to operate in a more RESTFul way.

2024050604(9mo ago)0129GPL-3.0-or-laterPHPCI failing

Since Jul 17Pushed 9mo agoCompare

[ Source](https://github.com/udir-moodle/webservice_restful)[ Packagist](https://packagist.org/packages/udir-moodle/webservice_restful)[ Docs](https://moodle.org/plugins/webservice_restful)[ RSS](/packages/udir-moodle-webservice-restful/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

[![ci](https://github.com/catalyst/moodle-webservice_restful/actions/workflows/ci.yml/badge.svg?branch=MOODLE_402_STABLE)](https://github.com/catalyst/moodle-webservice_restful/actions/workflows/ci.yml)

moodle-webservice\_restful
==========================

[](#moodle-webservice_restful)

A REStful webservice plugin for Moodle LMS

This plugin allows Moodle's webservice interface to operate in a more RESTFul way.
Instead of each webservice call having a URL query parameter define what webservice function to use, webservice functions are made available by discrete URLS.

This makes it easier to integrate Moodle with modern interfaces that expect a RESTful interface from other systems.

This plugin also supports sending requests to Moodle webservices using the JSON format.

Finally, by default all Moodle webservice requests return the HTTP status code of 200 regardless of the success or failure of the call. This plugin will return 4XX series status codes if calls are malformed, missing data or unauthorised. This allows external services communicating with Moodle to determine the success or failure of a webservice call without the need to parse the body of the response.

Why make this Plugin?
---------------------

[](#why-make-this-plugin)

There were two related reasons for making this plugin. The first was to solve a technical problem; interfacing Moodle to a service that required each Moodle webservice to be callable from a unique URL. The second was to advance the maturity of Moodle's webservice interface.

The "Richardson Maturity Model" () describes the maturity of a web applications API/ webservice interface in a series of levels.

[![Maturity Model](/pix/maturity.png?raw=true)](/pix/maturity.png?raw=true)

Moodle is currently Level 0 or in the "swamp of POX". As described be Fowler, Moodle "is using HTTP as a tunneling mechanism for your own remote interaction mechanism"

This plugin aims to extend the maturity of Moodle's webservice interface to "Level 1: Resources" by making each webservice function available as a discrete URL.

Supported Moodle Versions
-------------------------

[](#supported-moodle-versions)

Moodle versionBranchMoodle 4.2 - 4.4MOODLE\_402\_STABLEMoodle 3.9 - 4.1masterMoodle Plugin Installation
--------------------------

[](#moodle-plugin-installation)

The following sections outline how to install the Moodle plugin.

### Command Line Installation

[](#command-line-installation)

To install the plugin in Moodle via the command line: (assumes a Linux based system)

1. Get the code from GitHub or the Moodle Plugin Directory.
2. Copy or clone code into: `/webservice/restful`
3. Run the upgrade: `sudo -u www-data php admin/cli/upgrade` **Note:** the user may be different to www-data on your system.

### User Interface Installation

[](#user-interface-installation)

To install the plugin in Moodle via the Moodle User Interface:

1. Log into your Moodle as an Administrator.
2. Navigate to: *Site administration &gt; Plugins &gt; Install Plugins*
3. Install plugin from Moodle Plugin directory or via zip upload.

Moodle Plugin Setup
-------------------

[](#moodle-plugin-setup)

Once the plugin has been installed in Moodle, the following minimal setup is required:

1. Log into your Moodle as an Administrator.
2. Navigate to: *Site administration &gt; Plugins &gt; Webservices &gt; Manage protocols*
3. Enable the RESTful protocol by clicking the "eye icon" in the enable column for this protocol.

Moodle Webservice Setup
-----------------------

[](#moodle-webservice-setup)

Follow these instructions if you do not currently have any webservies enabled and/or unfamiliar with Moodle webservices.

There are several steps required to setup and enable webservices in Moodle, these are covered in the Moodle documentation that can be found at: [https://docs.moodle.org/34/en/Using\_web\_services](https://docs.moodle.org/34/en/Using_web_services)

It is recommended you read through these instructions first before attempting Moodle webservice Setup.

Accepted Content Types
----------------------

[](#accepted-content-types)

Data can be sent to Moodle webservices using the following encodings:

- application/json
- application/xml
- application/x-www-form-urlencoded

Use the 'Content-Type' HTTP header to notify Moodle which format is being used per request.

Returned Content Types
----------------------

[](#returned-content-types)

Data can be received from Moodle webservices using the following encodings:

- application/json
- application/xml

Use the 'Accept' HTTP header to notify Moodle which format to return per request.

Differences to Moodle Standard Webservice Interface
---------------------------------------------------

[](#differences-to-moodle-standard-webservice-interface)

When using the RESTful plugin there are several differences to other Moodle webservice plugins, these are summarised below:

- Webservice function as URL (slash parameter) \*\* Instead of being passed as a query parameter webservice functions are passed in the URL, e.g. [https://localhost/webservice/restful/server.php/core\_course\_get\_courses](https://localhost/webservice/restful/server.php/core_course_get_courses) this allows each webservice to appear as a unique URL endpoint.
- Webservice authorisation token as HTTP header \*\* Instead of being passed as a query parameter, authorisation tokens are passed using the 'Authorization' HTTP Header.
- Moodle response format as HTTP header \*\* Instead of being passed as a query parameter, the desired Moodle response format ispassed using the 'Accept' HTTP Header.

Sample Webservice Calls
-----------------------

[](#sample-webservice-calls)

Below are several examples of how to structure requests using the cURL command line tool.

### JSON Request

[](#json-request)

The following example uses the core\_course\_get\_courses webservice function to get the course with id 6. The request sent to Moodle and the response received back are both in JSON format.

To use the below example against an actual Moodle instance:

- Replace the {token} variable (including braces) with a valid Moodle authorisation token.
- Relace localhost in the URL in the example with the domain of the Moodle instance you want to use.

```

curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H 'Authorization: {token}' \
-d'{"options": {"ids":[6]}}' \
"https://localhost/webservice/restful/server.php/core_course_get_courses"

```

### XML Request

[](#xml-request)

The following example uses the core\_course\_get\_courses webservice function to get the course with id 6. The request sent to Moodle and the response received back are both in XML format.

To use the below example against an actual Moodle instance:

- Replace the {token} variable (including braces) with a valid Moodle authorisation token.
- Relace localhost in the URL in the example with the domain of the Moodle instance you want to use.

```

curl -X POST \
-H "Content-Type: application/xml" \
-H "Accept: application/xml" \
-H 'Authorization: {token}' \
-d'

         6

' \
"https://localhost/webservice/restful/server.php/core_course_get_courses"

```

### REST / Form Request

[](#rest--form-request)

The following example uses the core\_course\_get\_courses webservice function to get the course with id 6. The request sent to Moodle is in REST format and the response received back is in JSON format.

NOTE: This plugin can only accept requests in REST format. Responses must be in JSON or XML format.

To use the below example against an actual Moodle instance:

- Replace the {token} variable (including braces) with a valid Moodle authorisation token.
- Relace localhost in the URL in the example with the domain of the Moodle instance you want to use.

```

curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
-H 'Authorization: {token}' \
-d'options[ids][0]=6' \
"https://localhost/webservice/restful/server.php/core_course_get_courses"

```

### Mixed Request and Response

[](#mixed-request-and-response)

This Moodle webservice plug-in allows for requests and responses to be different formats.

The following example uses the core\_course\_get\_courses webservice function to get the course with id 6. The request sent to Moodle is in JSON format and the response received back is in XML format.

To use the below example against an actual Moodle instance:

- Replace the {token} variable (including braces) with a valid Moodle authorisation token.
- Relace localhost in the URL in the example with the domain of the Moodle instance you want to use.

```

curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/xml" \
-H 'Authorization: {token}' \
-d'{"options": {"ids":[6]}}' \
"https://localhost/webservice/restful/server.php/core_course_get_courses"

```

The received response will look like:

```

6

search test

1

10003

...

```

Error Examples
--------------

[](#error-examples)

The following cURL example will generate various types of errors. These are useful when testing.

### No Aauthorization Header

[](#no-aauthorization-header)

This request is missing the authorization header.

```

curl -i -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d'{"options": {"ids":[6]}}' \
"http://moodle.local/webservice/restful/server.php/core_course_get_courses"

```

### Invalid Token

[](#invalid-token)

This request contains an invalid webservice token.

```

curl -i -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H 'Authorization: xxx' \
-d'{"options": {"ids":[6]}}' \
"http://moodle.local/webservice/restful/server.php/core_course_get_courses"

```

### No Accept Header

[](#no-accept-header)

This request is missing the Accept header.

```

curl -i -X POST \
-H -i "Content-Type: application/json" \
-H 'Authorization: e71561c88ca7f0f0c94fee66ca07247b' \
-d'{"options": {"ids":[6]}}' \
"http://moodle.local/webservice/restful/server.php/core_course_get_courses"

```

Roadmap
-------

[](#roadmap)

The next big step will be to update the interface to "Level 2" that is support HTTP verbs, like get and post.
Which verb to use will likely be dependant on the ws function name that is being invoked.

If you have any suggestions for functionality, they can be requests by raising a GitHub issue: [https://github.com/catalyst/moodle-webservice\_restful/issues](https://github.com/catalyst/moodle-webservice_restful/issues)

Crafted by Catalyst IT
======================

[](#crafted-by-catalyst-it)

This plugin was developed by Catalyst IT Australia:

[![Catalyst IT](/pix/catalyst-logo.png?raw=true)](/pix/catalyst-logo.png?raw=true)

Contributing and Support
========================

[](#contributing-and-support)

Issues, and pull requests using github are welcome and encouraged!

[https://github.com/catalyst/moodle-webservice\_restful/issues](https://github.com/catalyst/moodle-webservice_restful/issues)

If you would like commercial support or would like to sponsor additional improvements to this plugin please contact us:

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance55

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

299d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a50175781f8a4d2f19fb9d128bf2c7c31c3cbdea6c5f2d2d6772a73586be5aa?d=identicon)[ajxudir](/maintainers/ajxudir)

---

Top Contributors

[![ajxudir](https://avatars.githubusercontent.com/u/161844445?v=4)](https://github.com/ajxudir "ajxudir (3 commits)")

---

Tags

pluginmoodlewebservice

### Embed Badge

![Health badge](/badges/udir-moodle-webservice-restful/health.svg)

```
[![Health](https://phpackages.com/badges/udir-moodle-webservice-restful/health.svg)](https://phpackages.com/packages/udir-moodle-webservice-restful)
```

###  Alternatives

[sybrew/the-seo-framework

An automated, advanced, accessible, unbranded and extremely fast SEO solution for any WordPress website.

47078.8k](/packages/sybrew-the-seo-framework)[phpcfdi/sat-ws-descarga-masiva

Librería para usar el servicio web del SAT de Descarga Masiva

16663.6k3](/packages/phpcfdi-sat-ws-descarga-masiva)[njasm/soundcloud

Soundcloud API Wrapper written in PHP with OAuth 2.0 support

100161.8k2](/packages/njasm-soundcloud)[tinify/magento2

Make your web shop faster by compressing your JPEG and PNG images. This plugin automatically optimizes your images by integrating with the popular image compression services TinyJPG and TinyPNG.

4345.8k](/packages/tinify-magento2)[camcima/camcima-soap-client

Wrapper around PHP SoapClient class

2672.0k2](/packages/camcima-camcima-soap-client)[deniskorbakov/laravel-data-scribe

A Scribe Plugin to generate API doc from spatie/laravel-data

124.3k](/packages/deniskorbakov-laravel-data-scribe)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
