It's a Decentraland scene to demonstrate how to incorporate an HTTP-REST API.
- GET /api/pixels
- get all pixels
- GET /api/pixels/pixel/?x=6&y=4
- get a single pixel at {x,y} coordinate from db
- PUT /api/pixels/pixel
- put a new pixel into the db
- POST /api/pixels/pixel/:id
- post an existing pixel back into the db
- DELETE /api/pixels/pixel/:id
- delete existing pixel
It uses MongoDB so please Install MongoDB before continuing.
# clone to your machine
git clone https://github.com/tcrowe/sample-sync-rest.git
cd sample-sync-rest
# from the project root
cd scene
# install node dependencies
npm install
# start the preview
npm start
(In another terminal window)
# from the project root
cd server
# install node dependencies
npm install
# start the server
npm start
Running the server and clicking around in the scene should automatically create the database.
You can confirm what is in the database by running:
mongodb
use sample-sync-rest
# switched to db sample-sync-rest
# list all pixels
db.pixels.find()
# ⚠️ delete all pixels
db.pixels.remove({})
If you notice that I've made an affront to correct TypeScript coding practices please forgive.
Others will want to use this as an example or starting place to fork from. If you see room for improvement please fork, mod, and send back here in a PR.
Thank you! 🤗