Skip to main content

Working with Cloudflare Workers

This brief tutorial will show you have to authenticate to the GDN using it's REST API and Cloudflare workers. It will then create a collection!

Auth and create first collection

const macrometaHost = ""
const authEndpoint = macrometaHost + "/_open/auth"
const collectionEndpoint = macrometaHost + "/_fabric/_system/_api/collection"
const type = "application/json;charset=UTF-8"
const authInfo = {
"email": "",
"password": "xxxxxx"

const newCollection = {
"name": "myCollection"
const getOptions = (requestBody, token) => ({
method: 'POST',
body: JSON.stringify(requestBody),
headers: {
authorization: token,
"content-type": type

async function handleRequest () {
const jwtRequest = await fetch(authEndpoint, getOptions(authInfo, ""))
const jwtResponse = await jwtRequest.json();
const jwtToken = `bearer ${jwtResponse.jwt}`

const collectionRequest = await fetch(collectionEndpoint, getOptions(newCollection, jwtToken))
const collectionResponse = await collectionRequest.json()
return new Response(JSON.stringify(collectionResponse))

addEventListener("fetch", event => {
return event.respondWith(handleRequest())


Response to collection creation


Now you have a collection created, you can check it out in the Macrometa console in Collections.