Requests and GET
Chapter lab: API foundations
This chapter works in a prepared project. Download it before the first task; it unpacks into its own folder.
Download ch11-api-foundations.zip
Or fetch and unpack it from a terminal in VS Code:
curl -fsSLO https://manykarim.github.io/robotframework-essentials-web/labs/ch11-api-foundations.zip && unzip -q ch11-api-foundations.zip && rm ch11-api-foundations.zipInvoke-WebRequest https://manykarim.github.io/robotframework-essentials-web/labs/ch11-api-foundations.zip -OutFile ch11-api-foundations.zip; Expand-Archive ch11-api-foundations.zip -DestinationPath .; Remove-Item ch11-api-foundations.zipOpen the folder in VS Code with code rfe-ch11-api-foundations (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-ch11-api-foundations/
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
The RF Demo Shop answers on a JSON API as well as a web page. Testing the API directly is fast and checks the contract at the seam — no browser needed.
The RequestsLibrary provides the HTTP keywords. GET <url> fetches a
resource and returns a response you can assert on.
Task 1 — Start the RF Demo Shop and keep it running
Section titled “Task 1 — Start the RF Demo Shop and keep it running”Start the shop in a terminal and leave it running:
uv run python demo_app/serve.pypython demo_app/serve.pypoetry run python demo_app/serve.pyIts API is at http://localhost:7273.
Done when
the API answers on its port.
Task 2 — GET the product catalog and check the count
Section titled “Task 2 — GET the product catalog and check the count”Goal: create checks/get.robot that GETs the product catalog, asserts a
200, and checks how many products come back.
Here is the same GET-then-assert shape against a different endpoint. Adapt it to
the catalog. (../resources/api.resource gives you ${API_URL}.)
Worked example — adapt it, don’t copy it
*** Settings ***Library RequestsLibraryResource ../resources/api.resource
*** Test Cases ***One Product Responds ${resp}= GET ${API_URL}/api/products/travel-mug Status Should Be 200 ${resp} Should Be Equal ${resp.json()}[slug] travel-mugDone when
the GET returns 200 and four products.
Hint 1
The catalog lives at ${API_URL}/api/products — GET it, then
Status Should Be 200 ${resp}.
Hint 2
The body is a JSON list, so assert its size with
Length Should Be ${resp.json()} 4.
Solution
*** Settings ***Library RequestsLibraryResource ../resources/api.resource
*** Test Cases ***Catalog Lists Products ${resp}= GET ${API_URL}/api/products Status Should Be 200 ${resp} Length Should Be ${resp.json()} 4Done when
the GET returns 200 and four products.
Check your understanding
Quick recall. Your first answer stays in this browser; the quiz never blocks your progress.
Which library drives HTTP requests in Robot Framework?
RequestsLibrary (robotframework-requests) provides GET/POST and response assertions.
Show the answer
Answer: RequestsLibrary — RequestsLibrary (robotframework-requests) provides GET/POST and response assertions.
Why test the API directly instead of only through the UI?
API tests are fast and verify the contract directly; they complement, not replace, UI tests.
Show the answer
Answer: It is faster and checks the contract at the seam — API tests are fast and verify the contract directly; they complement, not replace, UI tests.
Key terms
- RequestsLibraryconcept
- HTTP keywords for Robot Framework:
GET,POST,Status Should Be. - GETkeyword
${resp}= GET ${API_URL}/api/products— fetch a resource.