Loading Engineer Africa…
Loading Engineer Africa…
THE FREE ENGINEERING LAB
Make a request. Find the bug. Prove the fix.
Learn the testing habits that make software more dependable.
API FOUNDATIONS
…/ 03 lessons
Your next useful skill starts here.
LESSON 01 / 03 · 10 MIN
Turn an API requirement into explicit, executable checks.
Imagine you are shipping a checkout API for a community learning project. A successful request is only half the story. Your service must also explain why a bad request was rejected, so the application can help the person using it.
Our quote API accepts a whole-number quantity from 1 to 10. Each item costs 2,500 cents. A quantity of 2 therefore produces a total of 5,000 cents. A fractional or missing quantity returns status 400 and the error code INVALID_QUANTITY. The status describes the broad outcome; a stable error code explains the specific problem. Testing both catches failures that a status-only check would miss.
Teaching simulator: requests run entirely in your browser. They do not contact a server, create orders, or take payments.
400 INVALID_QUANTITY. Above 10: 400 QUANTITY_LIMIT.LEARN10 gives 10% off and ignores letter case. Any other value: 400 INVALID_COUPON.200 with currency, quantity, unitPrice, subtotal, discount, and total. Money uses USD cents. Unit price is 2500; total = subtotal − discount.The fractional-quantity test has the wrong expectation. Use the contract to repair it, then run all three cases against the reference build.
POST /sandbox/quote
// Send a request to inspect // its actual response here. // Nothing leaves your browser.
JSON data. Match the status and the body fields that matter.
03 / REVIEW THE EVIDENCE
Run your suite to see the result of every assertion.
The checklist below measures coverage as well as correctness.Check quantity 2 returns status 200 and total 5000
Check quantity 1.5 returns INVALID_QUANTITY with status 400
Check a missing quantity returns INVALID_QUANTITY with status 400
Run a reference suite with every assertion passing
Write the expected behavior from a requirement before looking at the implementation. Copying every observed response into a test can preserve a bug.