Speed as a strategy
Chapter lab: API in practice
This lesson continues in the same lab as the lesson before it. If you don’t have it yet, download it here.
Download ch12-api-in-practice.zip
Or fetch and unpack it from a terminal in VS Code:
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch12-api-in-practice.zip && unzip -q ch12-api-in-practice.zip && rm ch12-api-in-practice.zipInvoke-WebRequest https://manykarim.github.io/robotframework-essentials-web/labs/ch12-api-in-practice.zip -OutFile ch12-api-in-practice.zip; Expand-Archive ch12-api-in-practice.zip -DestinationPath .; Remove-Item ch12-api-in-practice.zipOpen the folder in VS Code with code rfe-ch12-api-in-practice (or File → Open Folder…) and accept the recommended RobotCode and Python extensions. Then set it up:
uv syncpython3 -m venv .venvsource .venv/bin/activatepip install -r requirements.txtpython -m venv .venv.venv\Scripts\Activate.ps1pip install -r requirements.txtKeep the environment active in every terminal where you run lesson commands.
poetry install --no-rootPython 3.13 or newer is required; uv installs it when it is missing.
Also needed for this lab
Start the RF Demo Shop in its own terminal and keep it running while you work:
uv run python demo_app/serve.pypython demo_app/serve.pypoetry run python demo_app/serve.pyOpen in browserNo setup? Try the lab right here: its files, an editor and a terminal, running in your browser.
What's inside
Directoryrfe-ch12-api-in-practice/
Directory.vscode/
- extensions.json
Directorychecks/
- smoke.robot
Directorydemo_app/
- api.py
- serve.py
- store.py
- web.py
Directoryresources/
- api.resource
- .gitignore
- .python-version
- LAB.md
- pyproject.toml
- README.md
- requirements.txt
- uv.lock
API checks are fast — a health check answers in a millisecond. That speed is a strategy: run a small, tagged smoke check first, and you learn in a second whether the service is even up before committing to the slow suites.
Close Part 3 with a fast, tagged API health check.
Task 1 — Tag a fast API health check as smoke
Section titled “Task 1 — Tag a fast API health check as smoke”Goal: create checks/speed.robot with one smoke-tagged test that GETs the
health endpoint and asserts a 200.
Here is the same tagged, fast check against a different endpoint. Adapt it to the health endpoint.
Worked example — adapt it, don’t copy it
*** Settings ***Library RequestsLibraryResource ../resources/api.resource
*** Test Cases ***Catalog Smoke [Tags] smoke ${resp}= GET ${API_URL}/api/products Status Should Be 200 ${resp}Done when
Api Smoke carries the smoke tag.
Hint 1
Give the test a [Tags] smoke line as its first step so --include smoke
selects it.
Hint 2
Hit the health endpoint: GET ${API_URL}/api/health, then
Status Should Be 200 ${resp}.
Solution
*** Settings ***Library RequestsLibraryResource ../resources/api.resource
*** Test Cases ***Api Smoke [Tags] smoke ${resp}= GET ${API_URL}/api/health Status Should Be 200 ${resp}Task 2 — Run only the smoke tests
Section titled “Task 2 — Run only the smoke tests”Filter the run to the smoke tag:
uv run robot --include smoke checksrobot --include smoke checkspoetry run robot --include smoke checksDone when
the API smoke test passes.
Check your understanding
Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.
A fast API smoke check is valuable because…
A one-second API health check fails fast when the service is down — run it before the slow suites.
Show the answer
Answer: it tells you in a second whether the service is up before slower tests run — A one-second API health check fails fast when the service is down — run it before the slow suites.
You run only the smoke tests with…
--include smokeselects the smoke-tagged tests.Show the answer
Answer:
robot --include smoke—--include smokeselects the smoke-tagged tests.
Key terms
- API smokeconcept
- A fast, tagged health check — run it first to fail fast when the service is down.