▫️Loan Calculator

Computes monthly payments for a loan based on the loan amount, interest rate, and loan term.

/loan-calculator

This endpoint calculates the monthly payment for a loan based on the provided loan amount, annual interest rate, and duration in years. It accepts a POST request with form data including the loanAmount, annualInterestRate, and durationYears. If any of the provided values are not valid numeric values, it returns a 400 error with a corresponding message. If the calculation results in a valid monthly payment, it returns the monthly payment rounded to 2 decimal places. If the calculation is invalid, it returns a 400 error with a corresponding message.

Headers:

  • Content-Type: application/x-www-form-urlencoded

Request Body (loanAmount, annualInterestRate, durationYears)

Form Data:

  • loanAmount: The amount of the loan.

  • annualInterestRate: The annual interest rate (in percentage).

  • durationYears: The duration of the loan in years.

Example:

loanAmount: 10000
annualInterestRate: 5
durationYears: 3

Response Upon successful calculation, the endpoint responds with the monthly payment amount.

Example:

{
    "monthlyPayment": "299.71"
}

Error Responses

  • Status Code: 400 Bad Request

    Body: "Please provide valid numeric values for loan amount, interest rate, and duration."

    Description: Occurs if any of the parameters are missing or not a valid number.

  • Status Code: 400 Bad Request

    Body: "Invalid calculation. Please check the input values."

    Description: Occurs if the calculation cannot be completed due to invalid input values, such as an interest rate of 0% over a 0 year duration, which are not mathematically viable for the formula.

This endpoint allows for a quick calculation of the monthly payments required for a loan based on the principal amount, the interest rate, and the loan duration. The calculation assumes that payments are made monthly and that the interest is compounded monthly as well.

Last updated