Class ApiResponse<T>

java.lang.Object
com.okta.sdk.resource.client.ApiResponse<T>
Type Parameters:
T - The type of the response body (e.g., List<User>, Group, etc.)

public class ApiResponse<T> extends Object
A stateless data object that represents a complete API response. This class packages together everything from an HTTP response: - The response body (deserialized data) - The response headers (including Link headers for pagination) - The HTTP status code (200, 404, etc.) Unlike the old approach which stored headers in a shared HashMap, ApiResponse is an immutable, thread-safe object that can be passed around without side effects. Example usage:
 ApiResponse<List<User>> response = apiClient.invokeAPIWithHttpInfo(...);
 
 int status = response.getStatusCode();              // e.g., 200
 List<User> users = response.getBody();             // The actual data
 Map<String, List<String>> headers = response.getHeaders();  // Response headers
 
 // Check for pagination
 List<String> linkHeaders = headers.get("Link");
 
Since:
17.0.0
  • Constructor Details

    • ApiResponse

      public ApiResponse(int statusCode, Map<String,List<String>> headers, T body)
      Constructs a new ApiResponse with the given status code, headers, and body.
      Parameters:
      statusCode - the HTTP status code (e.g., 200, 404, 500)
      headers - the response headers as a map (header name → list of values)
      body - the deserialized response body (can be null for 204 No Content)
  • Method Details

    • getStatusCode

      public int getStatusCode()
      Gets the HTTP status code from the response.
      Returns:
      the status code (e.g., 200 for success, 404 for not found)
    • getHeaders

      public Map<String,List<String>> getHeaders()
      Gets the response headers. Common headers include: - "Link": Pagination links (e.g., rel="next") - "Content-Type": Response content type - "X-Rate-Limit-Remaining": API rate limit info
      Returns:
      a map of header names to lists of header values
    • getBody

      public T getBody()
      Gets the deserialized response body. This is the actual data returned by the API, already converted from JSON into Java objects.
      Returns:
      the response body, or null if the response was empty (204 No Content)
    • toString

      public String toString()
      Overrides:
      toString in class Object