A 'Cloudflare Workers' API made in TypeScript.
Course: Intelligent Mobile Systems
Information: https://ju.se/en/study-at-ju/courses.html?courseCode=TIGK10&semester=20201&revision=1,000
Name | Terminal command | Website |
---|---|---|
itty-router | npm i itty-router | https://www.npmjs.com/package/itty-router |
wrangler | npm i @cloudflare/wrangler -g | https://developers.cloudflare.com/workers/cli-wrangler/install-update |
faunadb | npm i faunadb | https://docs.fauna.com/fauna/current/drivers/javascript.html |
Before running a development server, you'll need to setup the workspace with your own Cloudflare account by following these steps:
-
Create a local wrangler.toml file by copying the
wrangler.example.toml
file and renaming it. -
Login to Wrangler and authorize yourself by running the command:
wrangler login
- Get your specific unique Account ID by running the command:
wrangler whoami
- Insert the value of Account ID into the field account_id that exists in the newly created
wrangler.toml
file.
NOTE!
Make sure to not use the wrangler.prod.toml
file to develop with, as this configuration file only will be used to publish the API.
For a local development server, run this command:
wrangler dev
You can also use the Cloudflare Worker preview server by running this command:
wrangler preview
This project supports commitizen/cz-cli, which is a tool that generates commits that follows the standard Conventional Commits.
Add the files you want to commit by using git add
and then run the commitizen command cz
. Follow the steps and you will end up with a well formatted commit that you can push up to the repository via the command git push
.
This project comes with mocha tests which simply test that the request handler can handle each request method. npm test
will run your tests.
This project uses prettier
to format each files equally. To invoke, run npm run format
.
wrangler publish
Endpoint | Example body | Example response | Additional Information |
---|---|---|---|
GET /api/coord/:page | - |
[ [ { "collision": false, "X": 10, "Y": 10 } ], [ { "collision": false, "X": 9, "Y": 0 }, { "collision": false, "X": 5, "Y": 5 } ] ] |
/api/coord/1 will give the newest 5 routes, /2 will give the second newest 5 routes |
POST /api/coord |
{ "collision": false, "X":10, "Y":10, "session":14 } |
{ "ref": { "@ref": { "id": "299604759421125121", "collection": { "@ref": { "id": "coordinates", "collection": { "@ref": { "id": "collections" } } } } } }, "ts": 1621984214160000, "data": { "session": 14, "points": [ { "collision": false, "X": 10, "Y": 10 } ] } |
Provide a X and Y value as well as a session (this allows you to add coordinates to an existing session, provide non existing session to create a new) and a collision bool. |