RESTinstance
raw JSON → 1.8.0 verified Fri May 01 auth: no python
RESTinstance is a Robot Framework library for testing RESTful JSON APIs. It provides keywords for GET, POST, PUT, PATCH, DELETE and supports JSON schema validation. Currently at version 1.8.0, released periodically with compatible changes.
pip install robotframework-restinstance Common errors
error ImportError: No module named RESTinstance ↓
cause Library installed as 'robotframework-restinstance' but imported as 'RESTinstance' incorrectly.
fix
Install with: pip install robotframework-restinstance, then import: from RESTinstance import RESTinstance
error TypeError: __init__() got an unexpected keyword argument 'output_dir' ↓
cause RESTinstance does not accept `output_dir` in `__init__` when used outside Robot Framework; that is a Robot Framework construct.
fix
Do not pass
output_dir when initializing RESTinstance in Python directly. Use the default constructor: RESTinstance() error KeyError: 'response' ↓
cause Trying to access a response key directly on the RESTinstance object instead of the returned response object.
fix
RESTinstance methods return requests.Response objects. Use
response.json() or response.status_code. Warnings
gotcha RESTinstance is designed for Robot Framework, not for standalone Python tests. Using it outside Robot Framework may lead to unexpected behavior (e.g., missing 'output_dir' or logging). ↓
fix Use requests library directly for standalone Python API testing, or use within Robot Framework tests.
gotcha The library automatically validates responses if a schema is provided. If you set 'schema' in the keyword arguments, but the schema file path is wrong or the schema is invalid, the library raises an exception. This can be confusing if you expect no validation. ↓
fix Ensure schema files exist and are valid JSON Schema. If you don't need schema validation, omit the 'schema' parameter.
deprecated In version 1.8.0, use of `post`, `put`, `patch`, `delete` keywords with `body` as a string (JSON string) is required. Passing a Python dict may cause serialization issues in future versions. ↓
fix Always pass body as a JSON string (e.g., json.dumps(dict)) or use the `json` parameter if available (check docs).
gotcha The library verifies SSL certificates by default. If you are testing against a local development server with self-signed certificates, the request will fail. ↓
fix Pass `verify=False` in the keyword arguments (e.g., `api.get(url, None, verify=False)`).
Imports
- RESTinstance
from RESTinstance import RESTinstance
Quickstart
from RESTinstance import RESTinstance
import json
# Initialize the library
api = RESTinstance()
# Example: GET request
response = api.get('https://jsonplaceholder.typicode.com/posts/1', None)
print(response.status_code)
print(json.dumps(response.json(), indent=2))
# Example: POST request
body = '{"title": "foo", "body": "bar", "userId": 1}'
response = api.post('https://jsonplaceholder.typicode.com/posts', body, None)
print(response.status_code)