api_client.py
A flexible, generic HTTP API client built on requests.Session.
Classes
- class api_client.ApiClient(base_url=None, auth_token=None, config_file='api_config.ini', skip_auth_prompt=False)
Generic API client that can target any REST API.
- Parameters:
base_url (str) – API base URL (e.g.,
https://api.evercycle.io).auth_token (str) – Bearer token for Authorization header.
config_file (str) – INI file for persisting settings.
skip_auth_prompt (bool) – If True, do not prompt for a token.
- save_config() None
Persist current
base_urlandauth_tokento the INI file.
- discover_endpoints() dict | None
Attempt to discover API endpoints by probing common paths:
methods,endpoints,swagger,swagger.json,openapi,openapi.json,api-docs.Caches successful results in the INI file under
endpoints_cache.
- list_endpoints() None
Print discovered endpoints. Supports Swagger/OpenAPI
pathsformat and custommethodsformat.
- _print_nested_endpoints(data, prefix='') None
Recursively print nested endpoint dictionaries or lists.
- call_endpoint(endpoint, method='GET', params=None, data=None, headers=None)
Execute an HTTP request.
- Parameters:
endpoint (str) – URL path (joined with
base_url).method (str) – HTTP method.
params (dict) – Query parameters.
data (dict) – Request body (dict is auto-converted to JSON).
headers (dict) – Additional request headers.
- Returns:
Parsed JSON response, raw text, or None on error.
Side effects: Appends call metadata to
self.history.
- interactive_mode() None
Launch a text-based interactive menu (choices 1-6):
List endpoints
Call an endpoint (prompts for path, method, params, body)
View call history
Change base URL
Change authentication token
Exit
Functions
- api_client.main()
CLI entry point supporting:
--url,--token,--config,--endpoint,--method,--params,--data,--listFalls back to
interactive_mode()if no explicit operation given.