Using JavaScript

Contents

This section describes how to invoke the Guillotine API directly from a JavaScript client.

Example: Fetch content by type

In our example, we will use the http://localhost:8080/site/moviedb/master endpoint to make a request to the GraphQL API. More information about endpoints can be found here.

This endpoint expects to receive an HTTP POST request with the following properties in the body of the request:

  • A mandatory "query" String

  • An optional "variables" Object

Example: Fetch data from a javascript client
const query = `query($type:String){
    guillotine {
        queryDsl(query: {
          term: {
            field: "type",
            value: {
              string: $type
            }
          }
        }){
          ... on com_enonic_app_moviedb_Playlist {
            _id
            displayName
          }
        }
    }
}`;

const variables = {
    'type': 'com.enonic.app.moviedb:playlist'
};

fetch('http://localhost:8080/site/moviedb/master', {
    method: 'POST',
    body: JSON.stringify({
        query: query,
        variables: variables
    }),
    credentials: 'same-origin'
})
    .then(response => response.json())
    .then(console.log);

Contents

Contents