acquia / waterwheel.js

A generic JavaScript helper library to query and manipulate Drupal 8 via core REST and JSON API
https://github.com/acquia/waterwheel.js
233 stars 26 forks source link

How to get started? #56

Closed clemens-tolboom closed 6 years ago

clemens-tolboom commented 7 years ago

I have no good clue what to do exactly to get this up and running.

The example below is placed in Drupal root together with the dist/waterwheel.js file (example reported in #55)

<html>
<body>
<h1>Waterwheel</h1>
<script src="/waterwheel.js"></script>
<script>
    const waterwheel = new Waterwheel({
        base: 'http://drupal.d8',
        oauth: {
            grant_type: 'GRANT-TYPE',
            client_id: 'CLIENT-ID',
            client_secret: 'CLIENT-SECRET',
            username: 'USERNAME',
            password: 'PASSWORD',
            scope: 'SCOPE'
        }
    });

    waterwheel.api['user'].get(1)
        .then(res => {
        console.log(res)
        // Drupal JSON Object
    })
    .catch(err => {
        // err
    }
    )
    ;
</script>
</body>
</html>
iFarmGolems commented 7 years ago

+1

mattgrill commented 6 years ago

@clemens-tolboom

do I have to install oauth or can I install my test script in drupal root?

No. However I'd strongly suggest using authentication on your API.

what is grant_type: GRANT-TYPE, ?

This is the OAuth 2 grant type supported by the Simple OAuth Drupal module. Right now that's just password. I updated the documentation to note this.

where is a supposed to work html / browser example? See below.

The reason your example does not work is that Waterwheel does not know anything about your API in it's initial state. Waterwheel can configure itself to support your API, but you need to run .populateResources() prior to making any API requests.