({
apiUrl,
createResponseFiles = false,
apiBasePath = "",
enableCache
}: ApiConfig = { createResponseFiles: true })
| 112 | private readonly DEFAULT_API_URL = "http://localhost:8000"; |
| 113 | |
| 114 | constructor({ |
| 115 | apiUrl, |
| 116 | createResponseFiles = false, |
| 117 | apiBasePath = "", |
| 118 | enableCache |
| 119 | }: ApiConfig = { createResponseFiles: true }) { |
| 120 | /** |
| 121 | * Initializes the API client with a specified server URL, base path, caching options, and an option to create response files. |
| 122 | * |
| 123 | * @param apiUrl The base URL for the API server. If not specified, defaults to "http://localhost:8000". |
| 124 | * @param createResponseFiles Indicates if the client should create response files for each API call. This is useful for debugging or development purposes. Defaults to true. |
| 125 | * @param apiBasePath Base path to prefix API endpoints (e.g., "/v1"). |
| 126 | * @param enableCache Enable or disable caching for all API requests. Overrides the server's cache setting. |
| 127 | */ |
| 128 | this._apiUrl = apiUrl |
| 129 | ? removeAfterFirstSlash(apiUrl) |
| 130 | : this.DEFAULT_API_URL; |
| 131 | this._createResponseFiles = createResponseFiles; |
| 132 | this._apiBasePath = cleanBasePath(apiBasePath) as any; |
| 133 | this._enableCache = enableCache; |
| 134 | |
| 135 | // Check if API is running (note: this is synchronous in the original, but should be async in TS) |
| 136 | this.isApiRunning().then((isRunning) => { |
| 137 | if (!isRunning) { |
| 138 | throw new ApiException( |
| 139 | `API at ${this._apiUrl}${this._apiBasePath} is not running. Please check if the API is up and running.` |
| 140 | ); |
| 141 | } |
| 142 | }); |
| 143 | } |
| 144 | |
| 145 | private _writeJson(filename: string, data: any): void { |
| 146 | /** |
nothing calls this directly
no test coverage detected