Requests (Python)
Overview
The python-requests plugin generates Python code using the Requests library.
within API (plugin: python-requests, type: api) GET "https://api.example.com/users"Types
api
The main API context for making HTTP requests.
Modifiers:
| Modifier | Type | Description |
|---|---|---|
base | quoted | Base URL for all requests |
timeout | quoted | Request timeout |
headers | quoted | Default headers for requests |
Patterns:
| Pattern | Description |
|---|---|
GET <path> | HTTP GET request |
POST <path> body <body> | HTTP POST request with JSON body |
PUT <path> body <body> | HTTP PUT request with JSON body |
DELETE <path> | HTTP DELETE request |
expect failure | Expect following actions to fail (modifiers: error, capture) |
http_response
Response assertions returned by HTTP request patterns.
Patterns:
| Pattern | Description |
|---|---|
expect status <code> | Assert status code |
expect json <path> == <value> | Assert JSON value at path equals value |
failure_block
Child context for expect failure blocks. Accepts passthrough patterns from parent context.
Example
vanya 0.1"Create and fetch user"
within API (plugin: python-requests, type: api, base: "https://api.example.com") POST "/users" body '{"name": "Alice"}' expect status 201
GET "/users/1" expect status 200 expect json "name" == "Alice"Error Handling Example
vanya 0.1"Test error handling"
within API (plugin: python-requests, type: api, base: "https://api.example.com") expect failure (error: "requests.exceptions.HTTPError") GET "/nonexistent"