This project is an example of a REST api with Cloudflare Workers using cloudflare-worker-rest-api package
The cloudflare-worker-rest-api package makes it very easy to build REST apis since it is very similar to express framework.
I have divided the project into controllers, middlewares and routers in order for it to look like something closer to real world applications.
These are then imported on the index.js
file and connected with our app.
- The first thing you should do is go and create a Cloudflare Account if you have not done so
- Next up we need to setup our machine in order to deploy our build to cloudflare
- Click Here if you want to follow official setup docs
- Start by installing wrangler globaly on your system
npm i @cloudflare/wrangler -g
- After that, make sure to configure the global user for wrangler
- Follow on-screen instructions to get your api key
wrangler config
Enter API token:
superlongapitoken
- Now you are ready to clone this project on our machine
- After cloning the project, make sure to edit
wrangler.toml
file- fill
account_id
you your account id - fill
zone_id
you your zone id
- fill
- Don't forget to install necessary project packages
npm install
- Publish the project with wrangler
- it will install packages, build, and the deploy to cloudflare
npm run publish