{"id":18398750,"url":"https://github.com/mongodb-developer/cloudflare-worker-rest-api-atlas","last_synced_at":"2025-04-07T05:33:37.845Z","repository":{"id":37280076,"uuid":"425075351","full_name":"mongodb-developer/cloudflare-worker-rest-api-atlas","owner":"mongodb-developer","description":"This project explains how to build a REST API in a Cloudflare worker using MongoDB Realm Web JS and a MongoDB Atlas cluster to store the data.","archived":true,"fork":false,"pushed_at":"2024-09-18T15:01:37.000Z","size":77,"stargazers_count":63,"open_issues_count":0,"forks_count":26,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-02T01:14:01.490Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mongodb-developer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-11-05T20:24:16.000Z","updated_at":"2024-09-18T15:01:51.000Z","dependencies_parsed_at":"2024-03-29T12:29:07.532Z","dependency_job_id":"50c46d37-26d5-441c-b4c4-4f9f7bbaa66e","html_url":"https://github.com/mongodb-developer/cloudflare-worker-rest-api-atlas","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fcloudflare-worker-rest-api-atlas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fcloudflare-worker-rest-api-atlas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fcloudflare-worker-rest-api-atlas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fcloudflare-worker-rest-api-atlas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mongodb-developer","download_url":"https://codeload.github.com/mongodb-developer/cloudflare-worker-rest-api-atlas/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601378,"owners_count":20964861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T02:24:15.179Z","updated_at":"2025-04-07T05:33:37.215Z","avatar_url":"https://github.com/mongodb-developer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Notice: Repository Deprecation\nThis repository is deprecated and no longer actively maintained. It contains outdated code examples or practices that do not align with current MongoDB best practices. While the repository remains accessible for reference purposes, we strongly discourage its use in production environments.\nUsers should be aware that this repository will not receive any further updates, bug fixes, or security patches. This code may expose you to security vulnerabilities, compatibility issues with current MongoDB versions, and potential performance problems. Any implementation based on this repository is at the user's own risk.\nFor up-to-date resources, please refer to the [MongoDB Developer Center](https://mongodb.com/developer).\n\n\n# REST API with a Cloudflare Worker and a MongoDB Atlas Cluster\n\nThis 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.\n\n# How it Works\n\n- The MongoDB Atlas cluster stores the data in the `cloudflare.todos` collection.\n- A MongoDB Atlas App Services App manages the authentication and the collection access rules.\n- A Cloudflare worker uses the Realm Web SDK to authenticate and retrieve the data that is then exposed with a REST API.\n\n# Prerequisites\n\n- MongoDB Cloud account.\n- MongoDB Atlas Cluster (M0 is fine).\n- MongoDB Atlas App Services Application created \u0026 deployed.\n  - with Authentication API Keys turned on + an API key created.\n  - with a rule on the collection `cloudflare.todos` with a role \"owner\" with read and write access on all the fields, applied when `{\"owner\": \"%%user.id\"}`.\n- Cloudflare account (free plan is fine) with a `*.workers.dev` subdomain.\n\nTo deploy \u0026 test the API we need:\n- The Atlas App Services Application ID (top left corner).\n- The App authentication API key (in Authentication tab \u003e API Keys).\n- The Cloudflare account login/password.\n- The Cloudflare account ID (in Workers tab \u003e Overview).\n- The Cloudflare `*.workers.dev` subdomain (in Workers tab \u003e Overview).\n\n# Build and Deploy\n\nClone this repository\n```shell\ngit clone git@github.com:mongodb-developer/cloudflare-worker-rest-api-atlas.git\ncd cloudflare-worker-rest-api-atlas\n```\n\nEdit the file `wrangler.toml`\n- replace `CLOUDFLARE_ACCOUNT_ID` by your real Cloudflare account ID.\n- replace `MONGODB_REALM_APPID` by your real MongoDB Atlas App Services App ID.\n\nIf you want to use the bash files to test the REST API, edit the file `api_tests/variables.sh`:\n- replace `YOUR_SUBDOMAIN` so the final worker URL matches yours.\n- replace `YOUR_REALM_AUTH_API_KEY` with your App auth API key.\n\nRun the following commands:\n\n```shell\n$ npm i wrangler -g\n$ wrangler login\n$ wrangler deploy\n$ cd api_tests\n$ ./post.sh \"Write a good README.md for Github\"\n$ ./post.sh \"Commit and push\"\n$ ./findAll.sh\n$ ./findOne.sh \u003cOBJECT_ID\u003e # replace with an _id from the previous command\n$ ./patch.sh \u003cOBJECT_ID\u003e true\n$ ./findAll.sh # note that done=true now on your todo\n$ ./deleteOne.sh \u003cOBJECT_ID\u003e\n$ ./findAll.sh # only one left\n```\n\nYou can also navigate to your MongoDB Atlas Cluster and browse your collection `cloudflare.todos` to confirm the above tests.\n\n# Authors\n\n- [Luke Edwards](https://x.com/lukeed05)\n- [Maxime Beugnet](https://x.com/mbeugnet) \u003cmaxime@mongodb.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-developer%2Fcloudflare-worker-rest-api-atlas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmongodb-developer%2Fcloudflare-worker-rest-api-atlas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-developer%2Fcloudflare-worker-rest-api-atlas/lists"}