Tracks
/
Ballerina
Ballerina
/
Exercises
/
Calculator Service
Calculator Service

Calculator Service

Easy

Instructions

HTTP endpoints are better with type checking. Adding a Record type to a POST request will ensure the correct data is sent every time.

Objectives

  • Modify the provided code.
  • Add the necessary attributes to this record to accept two operands and an operator.
  • Add an HTTP resource function to accept a POST request on path '/calc'
  • The function should accept the Calculation record type as the payload and return a generic JSON object

Accepts

{ "operand1": 4, "operand2": 10.2, "operator": "+" }

Returns

{ "expression": "4+10.2", "result": 14.2 }
Edit via GitHub The link opens in a new window or tab
Ballerina Exercism

Ready to start Calculator Service?

Sign up to Exercism to learn and master Ballerina with 50 exercises, and real human mentoring, all for free.