java.lang.Object
overit.geocallapp.wfm.orchestrator.planning.utilities.rest.RestApiClient

public class RestApiClient extends Object
Client for making REST API calls with support for different authentication methods. This class provides methods for making HTTP requests to a REST API.
  • Field Details

  • Constructor Details

    • RestApiClient

      public RestApiClient(String baseUrl)
      Creates a new REST API client with the specified base URL and no authentication.
      Parameters:
      baseUrl - The base URL of the API
    • RestApiClient

      public RestApiClient(String baseUrl, AuthManager authManager)
      Creates a new REST API client with the specified base URL and authentication manager.
      Parameters:
      baseUrl - The base URL of the API
      authManager - The authentication manager to use (can be null for unauthenticated requests)
  • Method Details

    • withApiToken

      public static RestApiClient withApiToken(String baseUrl, String token)
      Creates a new REST API client with the specified base URL and API token. This is a convenience method that creates an API token authentication manager.
      Parameters:
      baseUrl - The base URL of the API
      token - The API token to use for authentication
      Returns:
      A new REST API client
    • withUsernamePassword

      public static RestApiClient withUsernamePassword(String baseUrl, String authUrl, String username, String password)
      Creates a new REST API client with the specified base URL and username/password authentication with JWT token. This is a convenience method that creates a username/password authentication manager.
      Parameters:
      baseUrl - The base URL of the API
      authUrl - The URL to use for authentication
      username - The username to use for authentication
      password - The password to use for authentication
      Returns:
      A new REST API client
    • withBasicAuth

      public static RestApiClient withBasicAuth(String baseUrl, String username, String password)
      Creates a new REST API client with the specified base URL and HTTP Basic Authentication. This is a convenience method that creates a basic auth authentication manager.
      Parameters:
      baseUrl - The base URL of the API
      username - The username to use for authentication
      password - The password to use for authentication
      Returns:
      A new REST API client
    • get

      public <T> Optional<T> get(String endpoint, Class<T> responseType) throws DAValidateException, org.springframework.web.client.RestClientException
      Makes a GET request to the specified endpoint.
      Type Parameters:
      T - The type of the response
      Parameters:
      endpoint - The API endpoint
      responseType - The type of the response
      Returns:
      An Optional containing the response
      Throws:
      DAValidateException - if authentication fails
      org.springframework.web.client.RestClientException - if the request fails
    • get

      public <T> Optional<T> get(String endpoint, Map<String,Object> queryParams, Class<T> responseType) throws DAValidateException, org.springframework.web.client.RestClientException
      Makes a GET request to the specified endpoint with query parameters.
      Type Parameters:
      T - The type of the response
      Parameters:
      endpoint - The API endpoint
      queryParams - The query parameters to add to the URL
      responseType - The type of the response
      Returns:
      An Optional containing the response
      Throws:
      DAValidateException - if authentication fails
      org.springframework.web.client.RestClientException - if the request fails
    • post

      public <R> Optional<R> post(String endpoint, Class<R> responseType) throws DAValidateException, org.springframework.web.client.RestClientException
      Makes a POST request to the specified endpoint with no request body.
      Type Parameters:
      R - The type of the response
      Parameters:
      endpoint - The API endpoint
      responseType - The type of the response
      Returns:
      An Optional containing the response
      Throws:
      DAValidateException - if authentication fails
      org.springframework.web.client.RestClientException - if the request fails
    • post

      public <T, R> Optional<R> post(String endpoint, T requestBody, Class<R> responseType) throws DAValidateException, org.springframework.web.client.RestClientException
      Makes a POST request to the specified endpoint with a request body.
      Type Parameters:
      T - The type of the request body
      R - The type of the response
      Parameters:
      endpoint - The API endpoint
      requestBody - The request body
      responseType - The type of the response
      Returns:
      An Optional containing the response
      Throws:
      DAValidateException - if authentication fails
      org.springframework.web.client.RestClientException - if the request fails
    • put

      public <T, R> Optional<R> put(String endpoint, T requestBody, Class<R> responseType) throws DAValidateException, org.springframework.web.client.RestClientException
      Makes a PUT request to the specified endpoint with a request body.
      Type Parameters:
      T - The type of the request body
      R - The type of the response
      Parameters:
      endpoint - The API endpoint
      requestBody - The request body
      responseType - The type of the response
      Returns:
      An Optional containing the response
      Throws:
      DAValidateException - if authentication fails
      org.springframework.web.client.RestClientException - if the request fails
    • patch

      public <T, R> Optional<R> patch(String endpoint, T requestBody, Class<R> responseType) throws DAValidateException, org.springframework.web.client.RestClientException
      Makes a PATCH request to the specified endpoint with a request body.
      Type Parameters:
      T - The type of the request body
      R - The type of the response
      Parameters:
      endpoint - The API endpoint
      requestBody - The request body
      responseType - The type of the response
      Returns:
      An Optional containing the response
      Throws:
      DAValidateException - if authentication fails
      org.springframework.web.client.RestClientException - if the request fails
    • delete

      public boolean delete(String endpoint) throws DAValidateException, org.springframework.web.client.RestClientException
      Makes a DELETE request to the specified endpoint.
      Parameters:
      endpoint - The API endpoint
      Returns:
      true if the request was successful
      Throws:
      DAValidateException - if authentication fails
      org.springframework.web.client.RestClientException - if the request fails
    • delete

      public boolean delete(String endpoint, Map<String,Object> queryParams) throws DAValidateException, org.springframework.web.client.RestClientException
      Makes a DELETE request to the specified endpoint with query parameters.
      Parameters:
      endpoint - The API endpoint
      queryParams - The query parameters to add to the URL
      Returns:
      true if the request was successful
      Throws:
      DAValidateException - if authentication fails
      org.springframework.web.client.RestClientException - if the request fails
    • getAuthManager

      public AuthManager getAuthManager()
      Gets the authentication manager used by this client.
      Returns:
      The authentication manager