J Chris A
J Chris A

Reputation: 1034

How do I access FaunaDB from my HTML page?

I see there is a release package with a CDN link, but nothing more in the README about how to access the driver once the script is included.

Upvotes: 1

Views: 198

Answers (1)

J Chris A
J Chris A

Reputation: 1034

I found that when you include it in the HTML page, like this:

<script src="//cdn.jsdelivr.net/faunadb/1.1/faunadb.js"></script>

A faunadb global variable is created, so you can use it like:

var q = faunadb.query;

var client = new faunadb.Client({
  secret: 'CHANGE-database-secret'
});

client.query(q.Paginate(q.Ref("indexes"))).then(function(result) {
  result.data.forEach(function(index){
    var p = document.createElement("p");
    p.innerText = index.value;
    document.body.appendChild(p);
  })
})

Upvotes: 1

Related Questions