Built for Cloudflare Workers. uses Cloudflare KV as Database
Blazing Fast Serverless π₯
- TOKEN based Authentication System
- Every type Error Handling
- Real time http response code
Need to pass Authorization
header along with AUTH_TOKEN. Otherwise it will return Unauthorized (http - 401)
curl -x POST https://backend.workers.dev/faculty -H 'Authorization: AUTH_TOKEN' -d '{name: "Xron Trix"}'
200
- OK204
- No Content400
- Bad Request401
- Unauthorized404
- Not Found405
- Method not Allowed409
- Data conflicts422
- Unprocessable Entity500
- Server error
/
- Check if Server is Online/faculty
- Access Faculty Members Data/member
- Access Regular Members Data/event
- Access Event Data
-
Faculty
{ name: "String", role: "String", image: "String", mobile: "String" }
-
Member
{ name: "String", role: "String", image: "String", mobile: "String", roll: "String" }
-
Event
{ title: "String", page: "String", image: "String", teams: [Array] # Optional in Creation }
POST /<API_ROUTE> {json in body}
- Create Single DataGET /<API_ROUTE>
- Read All DataGET /<API_ROUTE>/<ID>
- Read Single DataPUT /<API_ROUTE>/<ID>
- Update Single DataDELETE /<API_ROUTE>
- Delete All DataDELETE /<API_ROUTE>/<ID>
- Delete Single Data
-
Create
- Returns
http - 200
ID and Collection of new data in JSON on Success - Returns
http - 409
on Data Conflict - Returns
http - 422
on Unprocessable Entity - Returns
http - 500
on Creation error
- Returns
-
Read
- Returns
http - 200
requested data in JSON on Success - Returns
http - 404
on Not Found
- Returns
-
Update
- Returns
http - 200
Request Permitted! on Success - Returns
http - 404
on Not Found - Returns
http - 422
on Unprocessable Entity - Returns
http - 500
on Update error
- Returns
-
Delete
- Returns
http - 200
Request Permitted! on Success - Returns
http - 404
on Not Found - Returns
http - 500
on Update error
- Returns
-
Create a Cloudflare Account if haven't already π
-
Create a subdomain for your workers pages.
Your Projects will be visible as
https://project.SUB_DOMAIN.workers.dev
-
Install node.js if haven't already π
-
Install Wrangler as
npm install wrangler --save-dev
-
Login with Cloudflare Account
wrangler login
-
Clone This Repository
git clone https://github.com/XronTrix10/Cloudflare-RESTful-KV.git
-
Rename
wrangler.example.toml
file towrangler.toml
-
Rename
example.dev.vars
file to.dev.vars
-
Put a secret Auth Token in
.dev.vars
file. This Token will be used to Authenticate You with Your API -
Put the auth token in Wrangler as well
wrangler secret put AUTH_TOKEN
Enter The Same Token you Placed inside
.dev.vars
file -
Install dependencies
npm install
-
Create a KV Namespace in Cloudflare
wrangler kv:namespace create YOUR_NAMESPACE
NOTE: Replace your own desired Database Name with
YOUR_NAMESPACE
On Hitting Enter, an ID of the created namespace will be returned.
-
Put Binding in
wrangler.toml
file- Replace <NAMESPACE_ID> with the ID you got on namespace Creation
NOTE: β Don't Edit the Binding Name
binding = "DATABASE"
-
To Deploy/Test in Local
wrangler dev
-
To Deploy in Cloudflare
wrangler deploy
You can change the project name by editing the
name
field fromwrangler.toml
file before deploying your project
Live @Cloudflare
curl https://restapi-kv-demo.xrontrix.workers.dev
Server is up and running!