-
Notifications
You must be signed in to change notification settings - Fork 1
History
Tambapps edited this page Jun 3, 2022
·
4 revisions
You can enable a history feature allowing to keep track of requests made by your poet (this is disabled by default).
poet.enableHistory() // by default, the history size limit is 10
// but you can also specify it
poet.enableHistory(865)
The history is basically a list of HttpExchange
. It will keep track of all the exchanges, even the ones resulting in an error (non-successful HTTP code).
You can access them with the history
property.
makeHttpCalls(poet)
// print the last exchange made
println poet.history.last()
// can also access via reverse index
println poet.history[-1]
If you don't want to record the history for a particular call (e.g. a call returning a lot of data that you don't want to save in history), you can pass the boolean paramter skipHistory
like in the below example
poet.get('/api/big-file', skipHistory: true)
The HttpExchange
has the following properties
-
request
theokhttp3.Request
-
requestBody
thebody
you passed when making the request, ornull
-
rawRequestBody
theokhttp3.RequestBody
-
requestHeaders
aMap<String, List<String>>
containing request headers
-
response
theokhttp3.Response
-
responseCode
the response code -
responseBody
the parsed response body -
rawResponseBody
theokhttp3.ResponseBody
-
responseHeaders
aMap<String, List<String>>
containing response headers -
successful
whether there were a response with a 2XX response code
The HttpExchange responds to the groovy truth. It will evaluates to true
if the response is successful.