Skip to content

Latest commit

 

History

History
50 lines (32 loc) · 2.45 KB

api-calculator.md

File metadata and controls

50 lines (32 loc) · 2.45 KB

Backend Challenge - Calculator API

Introduction

The "Calculator API" challenge is designed to build a simple REST API that performs basic arithmetic operations (addition, subtraction, multiplication, division) based on user input.

Objectives

  • Set up a web server capable of handling API requests.
  • Implement endpoints for addition, subtraction, multiplication, and division operations.
  • Validate user input and handle edge cases (e.g., division by zero).
  • Understand HTTP methods (POST for sending data) and status codes.

Instructions

Step-by-Step Guide

  1. Objective: Your task is to develop a REST API that provides endpoints for basic arithmetic operations.

  2. Environment Setup: Choose your preferred programming language (e.g., JavaScript, Python, Java, C#) and set up the necessary environment.

  3. Implementation Details:

    • Create endpoints (/add, /subtract, /multiply, /divide) that accept input data via HTTP POST requests.
    • Validate input parameters and handle errors (e.g., invalid input, division by zero).
    • Implement logic to perform the requested arithmetic operation and return the result as JSON.
  4. Testing: Test your API using a HTTP client (e.g., Postman, curl).

    • Send POST requests to each endpoint with appropriate input data (e.g., numbers for calculation).
    • Verify that the response contains the correct result and the HTTP status code is 200 (OK) for successful requests.

Requirements

  • Basic knowledge of your chosen programming language.
  • Understanding of HTTP methods (POST) and status codes (e.g., 200 OK, 400 Bad Request).

Possible Improvements

After completing the basic Calculator API challenge, consider these improvements to enhance your API:

  • Decimal Support: Extend the API to handle decimal numbers for more precise calculations.
  • Additional Operations: Add endpoints for more complex operations (e.g., square root, exponentiation).
  • Input Validation: Implement stricter validation for input data to prevent unexpected behavior.
  • Error Handling: Enhance error messages and responses to provide clear feedback to API users.
  • Unit Testing: Write unit tests to validate the correctness of arithmetic operations and edge cases.

Conclusion

By completing this challenge and exploring possible improvements, you will gain practical experience in developing APIs for arithmetic operations and learn essential practices for building robust backend systems.

Happy coding!