Skip to content

History

Tambapps edited this page Jun 3, 2022 · 4 revisions

Enable history

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)

Http Exchange properties

The HttpExchange has the following properties

Request properties

  • request the okhttp3.Request
  • requestBody the body you passed when making the request, or null
  • rawRequestBody the okhttp3.RequestBody
  • requestHeaders a Map<String, List<String>> containing request headers

Response properties

  • response the okhttp3.Response
  • responseCode the response code
  • responseBody the parsed response body
  • rawResponseBody the okhttp3.ResponseBody
  • responseHeaders a Map<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.

Clone this wiki locally