Requests Library Skill
HTTP API tests with RequestsLibrary, a thin wrapper around Python requests: each call returns a requests.Response.
Use rf-restinstance instead when the suite imports Library REST or asserts JSON Schema / OpenAPI contracts.
Verified against RequestsLibrary 0.9.7, Robot Framework 7.4.
When to use
Load this skill first, before exploring the project, reading the suite or answering from memory, when a Robot Framework test calls an HTTP API with RequestsLibrary (Library RequestsLibrary):
- writing new API tests for an endpoint, or adding a check on a field of the JSON response;
- sessions, GET/POST/PUT/PATCH/DELETE, headers, bearer or basic auth, query parameters, JSON and multipart bodies,
expected_statusfor error responses; - a failing request (HTTPError, wrong status, SSL, timeouts);
- API tests in Robot Framework without naming a library: RequestsLibrary is the default.
Not this skill: suites that import REST (RESTinstance), or tests driven by JSON Schema/OpenAPI assertions, use rf-restinstance.
Installation
Install into the project environment (see rf-setup for uv/venv/Poetry, CI and troubleshooting; follow the project's existing tool):
bashuv add robotframework-requests
No post-install step.
Import and defaults
Default: one session per API, created in Suite Setup with TLS verification on, and path-only … On Session calls.
robotframework*** Settings *** Library RequestsLibrary Suite Setup Create Session api ${API_URL} verify=${True} Suite Teardown Delete All Sessions *** Test Cases *** Get User ${resp}= GET On Session api /users/1 Should Be Equal ${resp.json()}[name] Alice
Escape hatch: for one or two calls to full URLs, use the sessionless keywords (GET, POST, …) — see references/request-options.md.
Which keyword for which situation
| Situation | Use | Details |
|---|---|---|
| Call an endpoint of a shared base URL | GET On Session / POST On Session (path, not full URL) | references/request-options.md |
| One-off call to a full URL | GET, POST … (sessionless) | references/request-options.md |
| Send JSON / form / files | json=${dict} / data=${dict} / files=${files} | references/request-options.md |
| Query string | params=${dict} | references/request-options.md |
| Negative test (expect 4xx/5xx) | expected_status=404 on the call | references/request-options.md |
| Assert status after the call | Status Should Be 201 ${resp}, Request Should Be Successful | references/response-validation.md |
| Assert body or headers | Should Be Equal ${resp.json()}[id] ${1}, ${resp.headers}[Content-Type] | references/response-validation.md |
| Basic / digest / NTLM / client cert | Create Session … auth=, Create Digest Session, Create Ntlm Session, Create Client Cert Session | references/authentication.md |
| Bearer token for all later calls | Update Session api headers=${auth} | references/authentication.md |
| Unexpected error message | — | references/troubleshooting.md |
Agent workflow
- Look up each keyword before you use it:
robotcode doc keyword RequestsLibrary "<Keyword>"; find names withrobotcode doc keywords RequestsLibrary "<text>". Copy names and arguments exactly as robotcode shows them. - Write the test with the defaults above and the decision table.
- Check the changed files statically:
robotcode analyze code <changed files>(through the project environment, e.g.uv run robotcode …). Fix every error it reports. - Run them by longname:
robotcode robot -bl "<Suite.Sub.Test>"(longnames fromrobotcode discover tests), or pass a whole directory. Don't pass a single.robotfile: it skips the parent__init__.robot. - Read the results:
robotcode results show --failed, thenrobotcode results log -bl "<longname>". Don't parse output.xml by hand. - Fix the cause and go back to step 3 (static check). Stop when the tests pass or the failure is shown to be in the system under test, and say which.
Gotchas
- Every call asserts the status — with
expected_statusunset, any 4xx/5xx raisesHTTPError, because the library callsraise_for_status(). For negative tests passexpected_status=404(or a name such asnot found) instead of wrapping the call inRun Keyword And Expect Error. - No status ranges —
expected_statustakes one code, a status name, orany/anything;2xxfails withUnknownStatusError. For "any success" useexpected_status=anythingplusRequest Should Be Successful ${resp}. - Sessions skip TLS verification —
Create Sessiondefaults toverify=False, while sessionlessGET/POSTuse therequestsdefault (verify on). Passverify=${True}(or a CA bundle path) toCreate Session. json=vsdata=—json=${dict}serializes and setsContent-Type: application/json;data=${dict}form-encodes. Values fromCreate Dictionary/VARare strings, so writecount=${1}when the API expects a number; don't build JSON withEvaluate json.dumps(...).- Sessionless
auth=needs a tuple —GET ${url} auth=${list}fails withTypeError: 'list' object is not callable, because the list goes straight torequests.Create Session … auth=${list}works (the library wraps it in basic auth); sessionless calls need${auth}= Evaluate ("user", "pass"). - Sessions are global — the library scope is
GLOBAL, so an alias and its headers, cookies and auth live across tests and suites. Create sessions in Suite Setup and callDelete All Sessionsin Suite Teardown. =in a URL —GET On Session api /search?q=xfails withmissing 1 required positional argument: 'url', because Robot Framework parses…?q=xas a named argument. Passparams=${query}or writeurl=/search?q=x.Status Should Beargument order — the status comes first:Status Should Be 201 ${resp}. Without a response it checks the last response of any session.- Credentials are logged at INFO — session creation and each request log the
authtuple, theAuthorization: Basic …header and custom token headers in plain text, inlog.htmland inrobotcode reploutput (RequestsLibrary 0.9.7, observed with robotcode 2.8.0). Don't share raw logs; when logs leave the machine, run with--loglevel WARNor wrap the login calls inSet Log Level WARN…Set Log Level INFO.
When to read the references
| Read | When |
|---|---|
| references/request-options.md | choosing sessionless vs … On Session, body/params/files, timeouts, retries, TLS, expected_status |
| references/response-validation.md | asserting JSON bodies, lists, headers and cookies of a requests.Response |
| references/authentication.md | basic, digest, NTLM, client-certificate or token authentication |
| references/troubleshooting.md | a request fails with an error you don't recognise |
Examples in assets/examples/: basic-crud.robot, session-handling.robot, authentication-patterns.robot, file-upload.robot.
Companion Skills
| Need | Skill |
|---|---|
| API tests with RESTinstance / JSON Schema | rf-restinstance |
| Install Robot Framework or a library, fix the environment | rf-setup |
| Write tests, suites, user keywords, resources and variables in Robot Framework syntax | rf-language |
For running, discovering, keyword documentation, result analysis and debugging with the robotcode CLI, use the robotcode skill of the robotcode plugin (robotcode@robotframework-agent-plugins); the commands above work without it.


