0.1.0 • Published 7 years ago
moodle-rest-client v0.1.0
Moodle REST client for NodeJS
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
})