Show Menu
Cheatography

robotframework-okw-api-rest Quick Reference Cheat Sheet by

Quick reference for OKW REST API testing keywords (Robot Framework). Covers the complete test lifecycle: Start, Scope, Input, Action, Verify, Memorize, Stop. Designed for AI-friendly test generation — no JSON blocks, just field names and values.

Setup

Install library
pip install robotf­ram­ewo­rk-­okw­-ap­i-rest
Import in Settings
Library okw_ap­i_r­est.li­bra­ry.O­kw­Api­Res­tLi­brary WITH NAME RESTAPI
Minimum Python version
Python >= 3.10
Minimum RF version
robotf­ram­ework >= 6.0
YAML locator file required: locato­rs/­Ser­vic­eNa­me.yaml with __self­__.b­as­e_url and __self­__.c­on­ten­t_type. See README for full YAML examples.

Start / Stop

RESTStart service
Start REST service (load YAML)
RESTStart service env
Start with enviro­nment file
RESTStop
Stop REST service
YAML config separates URLs and creden­tials from test code. Enviro­nment files are searched in: ~/.okw­/env/ → $OKW_E­NV_DIR → locators/ → OS env vars.

Scope

RESTSe­lec­tEn­dpoint /path
Select endpoint (resets body/h­eaders)
RESTSe­tCo­ntext path
Navigate into nested JSON
RESTSe­tCo­ntext custom­er.a­ddress
Deeper nesting via dot notation
RESTSe­tCo­ntext items[0]
Select array element
RESTSe­lec­tEn­dpoint resets body, headers, and context. Each RESTSe­tCo­ntext replaces the previous one (flat, no stack).

Input

RESTSe­tValue field value
Set body field
RESTSe­tVa­lue­AsS­tring field value
Always send the value as a string (no auto-c­onv­ers­ion).
Example:
RESTSetValueAsString zipcode 01234 # -> "01234"
RESTSetValueAsString flag true # -> "­tru­e"
RESTSe­tValue ?param value
Set query parameter (? prefix)
RESTSe­tHeader name value
Set request header
RESTSe­tFile field filepath [mime_­type]
Set a file for multipart form-data upload. MIME type is auto-d­ete­cted. Call multiple times for multiple files.
Example:
RESTSetFile avatar photo.jpg
RESTSetFile document report.pdf application/pdf
Multiple files (same field):
RESTSetFile attach­ments file1.jpg
RESTSetFile attach­ments file2.jpg
? prefix sends field as URL query parameter instead of body field. Query parameters are not affected by RESTSe­tCo­ntext. Password fields are masked (*) in logs.

Action

RESTSe­ndR­equest GET
Send GET request
RESTSe­ndR­equest POST
Send POST request
RESTSe­ndR­equest PUT
Send PUT request
RESTSe­ndR­equest PATCH
Send PATCH request
RESTSe­ndR­equest DELETE
Send DELETE request
Request and response bodies are logged as formatted JSON. After sending, all RESTVerify and RESTMe­morize keywords operate on this response.

Auto Type Detection

RESTSe­tValue detects the JSON type automa­­ti­c­ally:

Zoltan -> "­Zol­tan­" (string)
42 -> 42 (integer)
3.14 -> 3.14 (float)
true / false -> true / false (boolean)
null / $NULL -> null
$EMPTY -> "­" (empty string)

Force string: Use RESTSet­Val­ueA­sString
RESTSetValueAsString zipcode 01234 # -> "­012­34"

Verify

RESTVe­rif­yStatus 200
Verify HTTP status code
RESTVe­rif­yValue field expected
Verify field value (exact match)
RESTVe­rif­yVa­lueWCM field text
Wildcard match (* ?)
RESTVe­rif­yVa­lueREGX field ^[a-f]+$
Regex match
RESTVe­rif­yHeader name expected
Verify response header
RESTVe­rif­yRe­spo­nseTime 500
Response time < 500ms
RESTVe­rif­yLi­stCount field expected
Verify the number of elements in a JSON array field. Contex­­t-­a­ware.
Example:
RESTVerifyListCount todos 3
RESTVerifyListCount items 0
Dot notation for nested fields: data.u­ser.name. With active context, fields resolve relative to context path. Respon­seTime checks elapsed time, not timeout.

Memorize

RESTMe­mor­ize­Value field NAME
Store response field value
RESTMe­mor­izeBody NAME
Store entire response body
$MEM{NAME}
Use stored value in next request
Use $MEM{NAME} in any keyword: RESTSe­tValue, RESTSe­tHe­ader, RESTSe­lec­tEn­dpoint. Missing keys cause an immediate error. Values persist across endpoints until RESTStop.

Tokens

$IGNORE
Skip keyword (no-op)
$EMPTY
Empty string
$MEM{KEY}
Stored value from RESTMe­mor­ize­Value
$NULL
Set field to JSON null.
Example:
RESTSetValue comment $NULL # -> "­com­men­t": null
RESTSe­tValue email $IGNORE → field not sent. RESTSe­tValue email $EMPTY → field sent as "­". RESTSe­tHeader x-auth­-token $MEM{T­OKEN} → inserts stored token value.

Phase Model

Start
RESTStart
Scope
RESTSe­lec­tEn­dpoint, RESTSe­tCo­ntext
Input
RESTSe­tValue, RESTSe­tVa­lue­AsS­tring, RESTSe­tVa­lue­AsList, RESTSe­tFile, RESTSe­tHeader
Action
RESTSe­ndR­equest
Verify
RESTVe­rif­yValue, RESTVe­rif­yVa­lueWCM, RESTVe­rif­yVa­lue­REGX, RESTVe­rif­ySt­atus, RESTVe­rif­yRe­spo­nse­Time, RESTVe­rif­yLi­stC­ount, RESTVe­rif­yHeader
Memorize
RESTMe­mor­ize­Value, RESTMe­mor­izeBody
Save
RESTSa­veR­esp­ons­eToFile
Stop
RESTStop
Config (YAML)
Retry, OAuth 2.0, Cookie Handling
Every REST test follows this sequence. Same pattern as OKW GUI keywords: StartApp → Select­Window → SetValue → ClickOn → Verify­Value → StopApp.

Total: 20 keywords

vs. Playwright (Code-­Based)

data: { title: 'Test' }
RESTSe­tValue title Test
expect­(re­spo­nse.st­atu­s()­).t­oBe­(201)
RESTVe­rif­yStatus 201
const body = await respon­se.j­son()
Not needed — automatic
expect­(bo­dy.t­it­le).to­Be(­'Test')
RESTVe­rif­yValue title Test
if (email) payloa­d.email = email
RESTSe­tValue email $IGNORE
{ nested: { key: 'val' } }
RESTSe­tCo­ntext nested + RESTSe­tValue key val
File Upload
OKW: RESTSe­tFile | PW: multipart option
Array Values
OKW: RESTSe­tVa­lue­AsList | PW: JSON inline
Auto Typing
OKW: automatic | PW: manual (JSON)
Cookie Handling
OKW: automatic | PW: contex­t.c­ook­ies()
Retry
OKW: YAML config | PW: custom logic
OAuth 2.0
OKW: YAML config | PW: custom logic
Response to File
OKW: RESTSa­veR­esp­ons­eToFile | PW: fs.wri­teF­ile()
No JSON syntax, no async/­await, no variable assign­ments. Field name + value — readable by testers, BAs, and AI. Same keyword model for GUI and API testing.

Save

RESTSa­veR­esp­ons­eToFile filepath
Save response body (bytes) to a file. Binary­­-safe (PDF, ZIP, images).
Direct­ories are created automa­­ti­c­ally. Existing file is overwr­i­tten (warning in log).
Supports: `$MEM{}, ~, $ENV_VAR, $IGNORE'
Example:
RESTSaveResponseToFile C:/tem­p/r­esp­onse.json
RESTSaveResponseToFile ~/down­­lo­a­d­s/­­rep­­or­t.pdf

Arrays

RESTSe­tVa­lue­AsList field val1 val2 ...
Compact:
RESTSetValueAsList tags a b c
# -> "­tag­s": ["a", "­b", "­c"]
RESTSe­tValue field[­index] value
Index syntax:
RESTSetValue scores[0] 42
RESTSetValue scores[1] 87
# -> "­sco­res­": [42, 87]
RESTSe­tVa­lue­AsList field
Empty array:
RESTSetValueAsList items
# -> "­ite­ms": []
RESTVe­rif­yLi­stCount field count
Verify length:
RESTVerifyListCount tags 3

File Upload

RESTSe­tFile field filepath [mime]
Set file for multipart upload. MIME is auto-d­­et­e­cted.
RESTSe­tFile + RESTSe­tValue
Text fields from RESTSe­tValue are sent as form fields alongside files.
Multiple files
all RESTSe­tFile multiple times — files accumu­­late until RESTSe­­le­c­t­En­­dpoint resets them.
RESTSe­ndR­equest automa­­ti­cally switches from JSON to multip­­ar­t­/­fo­­rm-data when files are present.
Example:
RESTSelectEndpoint /api/upload
RESTSetValue title Report
RESTSetFile file report.pdf
RESTSendRequest POST

Retry

retry_­count: 3
Max retries (default: 0 = off)
retry_­delay: 1000
Delay between retries in ms (default: 1000)
retry_on: 429,50­2,503
Status codes that trigger retry
Configure in YAML __self__ — no keyword needed. After all retries exhau­­sted: last status is kept, RESTVe­­ri­f­y­Status will fail.
Log:
<<< 429 — retry 1/3 (waiting 1000ms)
<<< 429 — retry 2/3 (waiting 1000ms)
<<< 200 OK

OAuth 2.0

auth_type: oauth2­_cl­ien­t_c­red­entials
Machin­e-t­o-m­achine API access
OAuth token endpoint
client_id / client­_se­cret: ${...}
From env file (~/.ok­­w/­e­n­v/­­env­­-t­e­s­t.yaml)
scope: read write
Space-­­se­p­a­rated scopes (optional)
RESTStart fetches the access token automa­­ti­c­ally. Author­­iz­a­tion: Bearer <to­ken> is set on every request.
Test:
RESTStart MyAPI env-test
RESTSelectEndpoint /api/data
RESTSendRequest GET
RESTVerifyStatus 200
RESTStop

Cookie Handling

Automatic (reque­sts.Se­ssion)
Server sends Set-Cookie -> cookie is stored. Subsequent requests send the cookie automa­­ti­c­ally. No new keyword needed.
Example (login with session cookie):
RESTSelectEndpoint /auth/login
RESTSetValue username admin
RESTSendRequest POST # Set-Cookie stored
RESTSelectEndpoint /api/data # cookie sent automa­tically
RESTSendRequest GET
RESTVerifyStatus 200

Header Logging

Request headers
Logged after >>> POST url in cleartext
Response headers
Logged after <<< 200 OK in cleartext
All request and response headers are logged in cleartext for maximum observ­­ab­i­lity. Body fields (password, token, secret) are masked with ***.
Log:
>>> POST https:­//a­pi.e­xa­mpl­e.c­om/­login
Headers:
Conten­t-Type: applic­ati­on/json
<<< 200 OK
Headers:
Set-Co­okie: JSESSI­­ON­ID­­=ab­­c123; Path=/; HttpOnly

YAML Config

Basic YAML
Servic­eNa­me.yaml in locators/ folder:

ServiceName:
__self__:
class: okw_api_rest.library.OkwApiRestLibrary
base_url: https:­//a­pi.e­xa­mpl­e.com
conten­t_type: applic­ati­on/json
With Enviro­nment File
YAML with ${VAR} placeh­olders — resolved from env file:

ServiceName:
__self__:
base_url: ${BASE_URL}
conten­t_type: ${CONTENT_TYPE}

env-te­st.yaml (in ~/.okw­/env/):
BASE_URL: https:­//a­pi.e­xa­mpl­e.com
CONTENT_TYPE: applic­ati­on/json
Authen­tic­ation (YAML)
Basic Auth:
'auth_type: basic
auth_user: ${API_USER}
auth_password: ${API_PASSWORD}

API Key:
auth_type: api_key
auth_header: X-API-Key
auth_key: ${API_KEY}

Bearer Token:
auth_type: bearer
auth_token: ${AUTH­_TO­KEN}'
SSL / Certif­icates
verify­_ssl: false # self-s­igned certs
client_cert: /.okw/certs/client.pem
client_key:
/.okw/certs/client.key
ca_bundle: ~/.okw­/ce­rts­/ca­-bu­ndl­e.pem
All settings go in __self__. Creden­tials use ${VAR} placeh­olders resolved from env files — no secrets in YAML. OAuth 2.0 and Retry are also configured here (see separate blocks).
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

            Python 3 Cheat Sheet by Finxter
          SEO Tips & Starter Guide Cheat Sheet