How to Use Google’s Firestore With Cloudflare’s EdgeWorker

Manuel Yang
CloudBoost
Published in
1 min readFeb 28, 2021

--

While Google recommends using their fire-admin-SDK for server-to-server communication, it unfortunately doesn’t work with a worker. Although we won’t get the convenience from an SDK, the REST API works just fine. Here are the steps I went through to make it work.

First, create a key with the firebase-adminsdk service account. Download the key as a JSON file.

Now that you have the private key, you can use this to get a JWT token to pass in the header of any REST call to authenticate it.

Here are some other examples with the REST API such as fetching a single document (GET), creating documents (POST), and deleting a document (DELETE). You’ll probably create a wrapper function to handle the headers but they will be explicitly displayed as an example.

Updating an existing document (PATCH) is a bit more complicated as you have to set the desired fields you want to edit in the query parameters as well.

I really love working with Cloudflare’s products and so I hoped this helped you out!

Sources

  1. https://m3hari.medium.com/firebase-database-using-rest-api-3b4c8982164e
  2. https://www.jeansnyman.com/posts/google-firestore-rest-api-examples/

--

--