{8.2.0-new} Response Status

After execution using {@link oajr.client2.RestRequest#run()} or {@link oajr.client2.RestRequest#complete()}, the following methods can be used to get the response status:

Example:

// Only interested in status code. int statusCode = client.get(URI).complete().getStatusCode();

Equivalent methods with mutable parameters are provided to allow access to status values without breaking fluent call chains.

Example:

// Interested in multiple values. Mutable<Integer> statusCode = Mutable.create(); Mutable<String> reasonPhrase = Mutable.create(); client.get(URI).complete().getStatusCode(statusCode).getReasonPhrase(reasonPhrase); System.err.println("statusCode="+statusCode.get()+", reasonPhrase="+reasonPhrase.get());

The assertion method is provided for quickly asserting status codes in fluent calls.

Example:

// Status assertion using a static value. String body1 = client.get(URI) .run() .assertStatus().code().isBetween(200,399) .getBody().asString(); // Status assertion using a predicate. String body2 = client.get(URI) .run() .assertStatus().code().passes(x -> x<400) .getBody().asString();