The most detailed free FDE + DevOps library: 140+ lessons, 70+ labs and 80 long-form articles, in English and Turkish. Start learning →

DevOps Foundations · Module 3: Safe automation with Bash and Python · Lab

Handle Timeout, 429 and Bad JSON Against a Fake API

50 min hands-on · Advanced

Local Linux shell plus Python 3; a fake API server (python http.server with a small handler, or netcat scripts) on localhost only.

Two ways to do this lab: in your browser on Killercoda (free, no install), or on your own machine as a local guide. Killercoda runs one free scenario at a time: if you see a waiting queue, close other Killercoda tabs and wait a minute.

Objectives

  • Serve the three bad behaviors locally: hangs, rate limits, malformed bodies
  • Handle each with timeouts, bounded retry and parsed responses
  • Cover every bad input with a test; use no real credentials
  1. Step 1

    Build the misbehaving API

    Serve four endpoints locally: /ok (valid JSON), /slow (sleeps 30s), /limited (first two hits 429 with Retry-After, then ok), /broken (200 with truncated JSON). Nothing leaves localhost.

  2. Step 2

    Write the hardened client

    Write a fetch-and-gate script with connect/total timeouts, max 3 attempts with backoff, 429 honored via Retry-After, and jq -e parsing with defaults. Every constant (attempts, sleeps, budget) visible at the top.

  3. Step 3

    Test the bad inputs

    Tests must cover /slow (bounded total time asserted), /limited (eventual success, exactly 3 requests), and /broken (clean nonzero exit, no crash). Show the suite green.

How to confirm it worked

  • All four endpoints served locally; nothing external contacted
  • Timeouts and retry budget are visible constants, measured total within budget
  • 429 honored rather than hammered; malformed JSON exits cleanly
  • Tests cover all three bad inputs and pass