Skip to content

Websocket microservice to facilitate communication between a javascript webapp and NoSQL database.

Notifications You must be signed in to change notification settings

kipppppp/CS361_Microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Fantasy Sports Microservice

Description

This project is a microservice that utilizes a websocket to facilitate information exchange between a javascript webapp and a NoSQL database. The microservice (written in python) returns JSON data with the overall score for the requested fantasy sports team. No specific request information is required at this point, but can be implemented if the function of the microservice expands to complete additional processes.

Languages Used

  • Python
  • JavaScript
  • HTML

Python Packages Used

  • asyncio
  • Websockets
  • JSON

Requesting/Receiving Data

Requesting

The code block below creates a websocket to request/read data sent from the localhost (127.0.0.1) at the specified port (65432). In this example, "button" is an html button element. When the button is selected, a request is made.

const heading = document.getElementById('main-heading');
const button = document.getElementById('microservice-btn');

// Add event listener to the button
button.addEventListener('click', () => {
    const ws = new WebSocket("ws://127.0.0.1:65432/")

    // Check if the microservice is running
    ws.addEventListener("error", (event) => {
        heading.textContent = "Microservice not running.";
    });

    // No errors, retreive data and update web page
    ws.onmessage = function(event){
    heading.textContent = event.data;
    ws.close();
    }
});

Receiving

In the above example, "heading" is an html header element. The "onmessage" function updates "heading" to display the JSON data received from the microservice.

The nested event listener will display error information if the microservice is not running.

    // Check if the microservice is running
    ws.addEventListener("error", (event) => {
        heading.textContent = "Microservice not running.";
    });

The received JSON data can be reformatted and displayed however necessary.

Screenshots

Before data request

Before request

After data request

Received data

Microservice not running when request is made

Error, microservice not running

UML Diagram


UML diagram


About

Websocket microservice to facilitate communication between a javascript webapp and NoSQL database.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors