moodle-rest-client

0.1.0 • Public • Published

Moodle REST client for NodeJS

npm version npm dependency status js-standard-style

Information

Node.js module for Moodle Rest Service integration

Setup

Npm

npm install moodle-rest-client --save

Yarn

yarn add moodle-rest-client

Usage

Instance

const {MoodleRestClient} = require('moodle-rest-client')
//Default use. Results in: http://your-moodle-url.com
const client = new MoodleRestClient('your-moodle-url.com', 'your-moodle-token')
//Using https. Results in: http://your-moodle-url.com
const client = new MoodleRestClient('your-moodle-url.com', 'your-moodle-token',
    {protocol: 'https'}
)
//Using diferent port. Results in: http://your-moodle-url.com:8080
const client = new MoodleRestClient('your-moodle-url.com', 'your-moodle-token',
    {port: 8080}
)
//Using subdirectory. Results in: http://your-moodle-url.com/moodle
const client = new MoodleRestClient('your-moodle-url.com', 'your-moodle-token',
    {subdirectory: 'moodle'}
)
//Using all together. Results in: https://your-moodle-url.com:8080/moodle
const client = new MoodleRestClient('your-moodle-url.com', 'your-moodle-token',
    {protocol: 'https', port: 8080, subdirectory: 'moodle'}
)

Request

The method client.send expects three params:

  • wsFunction: Moodle webservice function name
  • Key: Moodle webservice function parameter key
  • Value: Moodle webservice function parameter value

Get user sample

client.send('core_user_get_users', 'criteria', [{key: 'id', value: 2}])
  .then((data) => {
    //Handle the result
  })
  .catch((error) => {
    //Handle the request error
  })

Create user sample

let data = [{
    username: 'username',
    password: 'Strong@pass123',
    firstname: 'Firstname',
    lastname: 'Lastname',
    email: 'user@provider.com'
}]
client.send('core_user_create_users', 'criteria', [{key: 'id', value: 2}])
  .then((data) => {
    //Handle the result
  })
  .catch((error) => {
    //Handle the request error
  })

Reference

Readme

Keywords

none

Package Sidebar

Install

npm i moodle-rest-client

Weekly Downloads

0

Version

0.1.0

License

Apache-2.0

Last publish

Collaborators

  • virgilio.missao