Skip to content

client-side and server-side javascript REST API example that receive and send AVRO buffer in request/response

License

Notifications You must be signed in to change notification settings

rondinif/avro-rest-js

Repository files navigation

avro-rest-js

simple lab applying avsc and learn by doing:

  1. how to create a trivial nodejs express REST API server that receive and send avro buffer in request/response
  2. how to call REST API that send and receive avro buffer client side javascript

Badges

Sonarcloud Status

Sonarcloud sqale_index

Sonarcloud security_rating Sonarcloud sqale_rating Sonarcloud reliability_rating

Sonarcloud ncloc Sonarcloud bugs Sonarcloud vulnerabilities Sonarcloud duplicated_lines_density Sonarcloud code_smells

License

Getting started

Clone the project

git clone https://github.com/rondinif/avro-rest-js.git

Install dependencies and dev-dependencies

npm install

Run and Debug

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

Start Mongodb

if you have mongod istalled

$ mongod --config  ${YOUR_MONGO_CONFIGURATION} 

if you want to run mongo in a container

$ cd docker 
$ docker-compose up

if you want to install locally only the mongo client

$ brew tap mongodb/brew
$ brew install mongodb-community-shell

Start Server side API

$ npm run start

or:

$ DEBUG=api:* npm start

Build and Start Client web-app with python

$ 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 ...

...or start Client web-app with light-server

$ 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

Connect the mongo client to perform sone queries

if you have mongod installed and want to use the local mongo client

$ mongo
MongoDB shell version: 3.0.3
connecting to: test

if run mongod in a container and want to use the mongo client installed on the host

$ 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

if run mongod in a container and want to use the mongo client from the container

$ 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

perform some queries

> show dbs
Tododb  0.078GB
> use Tododb
switched to db Tododb
> db.getCollectionNames()
[ "system.indexes", "tasks" ]
> db.tasks.find()

About

client-side and server-side javascript REST API example that receive and send AVRO buffer in request/response

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages