absar

Simple calculator API hosted on APIMATIC

Usage no npm install needed!

<script type="module">
  import absar from 'https://cdn.skypack.dev/absar';
</script>

README

Getting Started with Calc

Getting Started

Introduction

Simple calculator API hosted on APIMATIC

Install the Package

Run the following command from your project directory to install the package from npm:

npm install absar@1.0.0

You can also view the package at: https://www.npmjs.com/package/absar/v/1.0.0

Initialize the API Client

The API client can be initialized as follows:

const lib = require('lib');
const configuration = lib.Configuration;

Client Class Documentation

Calc Client

The gateway for the SDK. This class acts as a factory for the Controllers and also holds the configuration of the SDK.

Controllers

Name Description
simpleCalculator Gets SimpleCalculatorController

API Reference

List of APIs

Simple Calculator

Overview

Get singleton instance

The singleton instance of the SimpleCalculatorController class can be accessed from the API Client.

const lib = require('lib');
const controller = lib.SimpleCalculatorController;

Get Calculate

Calculates the expression using the specified operation.

:information_source: Note This endpoint does not require authentication.

getCalculate(input)
Parameters
Parameter Type Tags Description
operation OperationTypeEnum Template, Required The operator to apply on the variables
x double Query, Required The LHS value
y double Query, Required The RHS value
Response Type

double

Example Usage
let input = [];
let operation = lib.OperationTypeEnum.MULTIPLY;
input['operation'] = operation;

let x = 222.14;
input['x'] = x;

let y = 165.14;
input['y'] = y;

const promise = controller.getCalculate(input);
promise.then((response) => {
    // this block will be executed on successful endpoint call
    // `response` will be of type 'double'
}, (err) => {
    // this block will be executed on endpoint call failure
    // `err` is an 'object' containing more information about the error
});
Errors
HTTP Status Code Error Description Exception Class
412 Could not compute the requested calculation CouldNotComputeException

Model Reference

Enumerations

Operation Type

Possible operators are sum, subtract, multiply, divide

Class Name

OperationTypeEnum

Fields
Name Description
SUM Represents the sum operator
SUBTRACT Represents the subtract operator
MULTIPLY Represents the multiply operator
DIVIDE Represents the divide operator

Exceptions

Could Not Compute

Is thrown when invalid input is given such as div by zero

Class Name

CouldNotComputeException

Fields
Name Type Tags Description
serverMessage string Required Represents the server's exception message
serverCode int Required Represents the server's error code
Example (as JSON)
{
  "ServerMessage": "ServerMessage6",
  "ServerCode": 170
}