simple lab applying avsc and learn by doing:
- how to create a trivial nodejs express REST API server that receive and send avro buffer in request/response
- how to call REST API that send and receive avro buffer client side javascript
git clone https://github.com/rondinif/avro-rest-js.git
npm install
In this lab you want to open 3 terminals:
- one for mongodb ( start mongod and run queries in mongo shell )
- one to run the sever-side ( classi NodeJS Express REST-API server on port 3000)
- one to run the client-side ( html, javascript served on port 9090 )
and 1 browser: hopefully Chrome with DevTools for debugging client-side JS
$ mongod --config ${YOUR_MONGO_CONFIGURATION}
$ cd docker
$ docker-compose up
$ brew tap mongodb/brew
$ brew install mongodb-community-shell
$ npm run start
or:
$ DEBUG=api:* npm start
$ npm --ignore-scripts=false run build-client-side
> [email protected] build-client-side /Users/ronda/projects/learning-avro/lab05-avro-rest/avro-rest-js
> browserify ./client-side/main.js -o ./client-side/bundle.js --debug
$ npm --ignore-scripts=false run serve-client-side
> [email protected] serve-client-side /Users/ronda/projects/rondinif/avro-rest-js
> cd client-side; python -m SimpleHTTPServer 9090 ; cd ..
Serving HTTP on 0.0.0.0 port 9090 ...
$ npm --ignore-scripts=false run start-client-side
> [email protected] start-client-side /Users/ronda/projects/rondinif/avro-rest-js
> npx light-server -s ./client-side -p 9090 -w 'client-side/**/*.js, client-side/**/*.html'
light-server is listening at http://0.0.0.0:9090
serving static dir: ./client-side
light-server is watching these files: client-side/**/*.js, client-side/**/*.html
when file changes,
this event will be sent to browser: reload
$ mongo
MongoDB shell version: 3.0.3
connecting to: test
$ mongo docker_mongodb_1
MongoDB shell version v4.2.0
connecting to: mongodb://127.0.0.1:27017/docker_mongodb_1?compressors=disabled&gssapiServiceName=mongodb
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a2315a01ae43 mongo:3.2 "docker-entrypoint.s…" About an hour ago Up 6 seconds 0.0.0.0:27017->27017/tcp docker_mongodb_1
$ docker exec -it docker_mongodb_1 /bin/bash
> show dbs
Tododb 0.078GB
> use Tododb
switched to db Tododb
> db.getCollectionNames()
[ "system.indexes", "tasks" ]
> db.tasks.find()