coding-to-music / coding-to-music.github.io

https://pandemic-overview.readthedocs.io/en/latest/index.html
MIT License
2 stars 8 forks source link

REST API with a Cloudflare Worker and a MongoDB Atlas Cluster #348

Open coding-to-music opened 2 years ago

coding-to-music commented 2 years ago

REST API with a Cloudflare Worker and a MongoDB Atlas Cluster

https://www.mongodb.com/developer/how-to/cloudflare-worker-rest-api-realm/

This project explains how to build a REST API in a Cloudflare worker using MongoDB Realm Web SDK and a MongoDB Atlas cluster to store the data.

https://github.com/coding-to-music/cloudflare-worker-rest-api-realm-atlas

How it Works

Prerequisites

To deploy & test the API we need:

Build and Deploy

Clone this repository

git clone git@github.com:mongodb-developer/cloudflare-worker-rest-api-realm-atlas.git
cd cloudflare-worker-rest-api-realm-atlas

Edit the file wrangler.toml

If you want to use the bash files to test the REST API, edit the file api_tests/variables.sh:

Run the following commands:

$ npm i @cloudflare/wrangler -g
$ wrangler login
$ wrangler publish
$ cd api_tests
$ ./post.sh "Write a good README.md for Github"
$ ./post.sh "Commit and push"
$ ./findAll.sh
$ ./findOne.sh <OBJECT_ID> # replace with an _id from the previous command
$ ./patch.sh <OBJECT_ID> true
$ ./findAll.sh # note that done=true now on your todo
$ ./deleteOne.sh <OBJECT_ID>
$ ./findAll.sh # only one left

You can also navigate to your MongoDB Atlas Cluster and browse your collection cloudflare.todos to confirm the above tests.

Authors