{title:'Response Status', created:'8.1.0', updated:'9.0.0'}

After execution using {@link oajrc.RestRequest#run()} or {@link oajrc.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. | Value<Integer> statusCode = Value.empty(); | Value<String> reasonPhrase = Value.empty(); | | 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 content1 = client.get(URI) | .run() | .assertStatus().asCode().isBetween(200,399) | .getContent().asString(); | | // Status assertion using a predicate. | String content2 = client.get(URI) | .run() | .assertStatus().asCode().is(x -> x<400) | .getContent().asString();