-
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
-
requesttheokhttp3.Request -
requestBodythebodyyou passed when making the request, ornull -
rawRequestBodytheokhttp3.RequestBody -
requestHeadersaMap<String, List<String>>containing request headers
-
responsetheokhttp3.Response -
responseCodethe response code -
responseBodythe parsed response body -
rawResponseBodytheokhttp3.ResponseBody -
responseHeadersaMap<String, List<String>>containing response headers -
successfulwhether 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.