Frontend Broadsoft - QuinnBast/SaskTel-Communication-Portal GitHub Wiki

Broadsoft

The BroadSoft.js file is used to manage to send and to receive all requests to and from the server. This component has login and logout functions which perform their respective operations (although, these functions should not be used directly. Instead, use the Auth.login() and Auth.logout() functions to ensure the Auth component performs its necessary operations). The Auth component manages all of the user authentication and token management that is required for the application, and thus a developer doesn't need to worry about managing tokens.

Sending requests

The most commonly used function is the sendRequest function which sends an http request to the backend web server. This function takes in an object which defines what url, method, and data should be sent to the server. Below is an example of how to use the function:

import BroadSoft from "BroadSoft.js"
let request = {
    endpoint: "/user/<user>/services"
    method: "GET"
}
BroadSoft.sendRequest(request);

Working with Promises

This function returns a Promise that, if successful will resolve, and if unsuccessful with reject. If you would like another action to be performed, but only be performed after a response is received from the request, the returned Promise can be taken advantage of.

Performing operations after a request

import BroadSoft from "BroadSoft.js"
BroadSoft.sendRequest({endpoint: "someEndpoint"}).then(
    (successResponse) => {
        // Do something if a request is successful
    },
    (failureResponse) => {
        // Do something if a request failed
    }
);

The above uses arrow notation to perform functions. It could also be replaced as follows:

import BroadSoft from "BroadSoft.js"
BroadSoft.sendRequest({endpoint: "someEndpoint"}).then(
    function(successResponse) {
        // Do something if a request is successful
    },
    function(failureResponse){
        // Do something if a request failed
    }
);
⚠️ **GitHub.com Fallback** ⚠️