RestBase Connection¶
-
class
RestBase
(url, username=None, password=None, api_base_path=None, verify_ssl=False, DEBUG=False, con_type=None)¶ Bases:
object
Parent class for all REST-like connections
Parameters: - url – URL or IP address of the target machine
- username – Username for authentication
- password – Password for authentication
- api_base_path – Base path for the API resource, such as “/api/v1”
- verify_ssl – Enable SSL certificate verification. For self-signed certificates, set this to False
- DEBUG – Enable debugging output
- con_type – String representation of connection type, set by child classes
Connection-specific function for handling authorization. Overridden by child classes
Returns: None
-
_delete
(path, params)¶ Wrapper function for DELETE method of the requests library
Parameters: - path – Path of the API resource used in URL
- params – Parameters for the request
Returns: Instance of
requests
response object
-
_get
(path, params=None)¶ Wrapper function for GET method of the requests library
Parameters: - path – Path of the API resource used in URL
- params – Parameters for the request
Returns: Instance of
requests
response object
-
_initialize
()¶ Function for credentials loading and session preparation. Might be overwritten in child classes
Returns: None
-
_post
(path, data=None, files=None, params=None)¶ Wrapper function for POST method of the requests library
Parameters: - path – Path of the API resource used in URL
- data – Data payload for POST request. JSON string
- files (dict) – Dictionary with files to upload
- params – Parameters for the request
Returns: Instance of
requests
response object
-
_put
(path, data=None, files=None, params=None)¶ Wrapper function for PUT method of the requests library
Parameters: - path – Path of the API resource used in URL
- data – Data payload for POST request. JSON string
- params – Parameters for the request
Returns: Instance of
requests
response object
-
_response_handler
(response)¶ Function for handling request’s response objects. Main purpose of this action is to handle HTTP return codes. In case of JSON formatted reply, returns this data as dictionary. In case of errors, either string representation of data is returned, or None. Status code is returned alongside the content to allow further processing if needed.
Parameters: response – Instance of request’s response object. Returns: content, status code