Loan Calculator API

A lightweight REST API that calculates loan payment metrics given amount, annual rate, and term in years. It returns monthly payment, total payment, and total interest using the standard amortization formula.

Base URL

https://www.promptbox.cn/api/loan.php

Methods

GET and POST (JSON)

Query Parameters (GET)

Parameter Type Required Example Description
amount float Yes 200000 Principal loan amount
rate float Yes 5.5 Annual interest rate in percent
years integer Yes 30 Term length in years

Request Body (POST JSON)

{
  "amount": 200000,
  "rate": 5.5,
  "years": 30
}

Response

Success

{
  "monthlyPayment": 1135.58,
  "totalPayment": 408808.80,
  "totalInterest": 208808.80,
  "inputs": {
    "amount": 200000.00,
    "rate": 5.50,
    "years": 30.00
  }
}

Error

{
  "error": "Missing or invalid 'amount'. Must be > 0."
}

Examples

1. GET Example

GET /api/loan.php?amount=200000&rate=5.5&years=30
{
  "monthlyPayment": 1135.58,
  "totalPayment": 408808.80,
  "totalInterest": 208808.80,
  "inputs": {
    "amount": 200000.00,
    "rate": 5.50,
    "years": 30.00
  }
}

2. POST Example

POST /api/loan.php
Content-Type: application/json

{
  "amount": 200000,
  "rate": 5.5,
  "years": 30
}
{
  "monthlyPayment": 1135.58,
  "totalPayment": 408808.80,
  "totalInterest": 208808.80,
  "inputs": {
    "amount": 200000.00,
    "rate": 5.50,
    "years": 30.00
  }
}

3. Error Example

GET /api/loan.php?amount=0&rate=5&years=30
{
  "error": "Missing or invalid 'amount'. Must be > 0."
}

Notes