You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- feat: add `execute_api_request` and `execute_streamed_api_request` methods to `OpenFgaClient` and `OpenFgaApi` for making arbitrary HTTP requests to any OpenFGA API endpoint with full auth, retry, and telemetry support (#252) - thanks @kcbiradar
6
+
7
+
### Breaking Changes
8
+
9
+
- The `_return_http_data_only`, `_preload_content`, `_request_auth`, `async_req`, and `_request_timeout` kwargs have been removed from all `OpenFgaApi` and `SyncOpenFgaApi` endpoint methods. These were internal implementation details not intended for external use. `_return_http_data_only` is now hardcoded to `True`; all endpoint methods return the deserialized response object directly. Users relying on `_with_http_info` methods returning a `(data, status, headers)` tuple should use `execute_api_request` instead.
In certain cases you may want to call other APIs not yet wrapped by the SDK. You can do so by using the `execute_api_request` method available on the `OpenFgaClient`. It allows you to make raw HTTP calls to any OpenFGA endpoint by specifying the HTTP method, path, body, query parameters, and path parameters, while still honoring the client configuration (authentication, telemetry, retries, and error handling).
1267
+
1268
+
For streaming endpoints (e.g. `streamed-list-objects`), use `execute_streamed_api_request` instead. It returns an `AsyncIterator` (or `Iterator` in the sync client) that yields one parsed JSON object per chunk.
1269
+
1270
+
This is useful when:
1271
+
- You want to call a new endpoint that is not yet supported by the SDK
1272
+
- You are using an earlier version of the SDK that doesn't yet support a particular endpoint
1273
+
- You have a custom endpoint deployed that extends the OpenFGA API
1274
+
1275
+
#### Example: Calling a Custom Endpoint with POST
1276
+
1277
+
```python
1278
+
# Call a custom endpoint using path parameters
1279
+
response =await fga_client.execute_api_request(
1280
+
operation_name="CustomEndpoint", # For telemetry/logging
1281
+
method="POST",
1282
+
path="/stores/{store_id}/custom-endpoint",
1283
+
path_params={"store_id": FGA_STORE_ID},
1284
+
body={
1285
+
"user": "user:bob",
1286
+
"action": "custom_action",
1287
+
"resource": "resource:123",
1288
+
},
1289
+
query_params={
1290
+
"page_size": 20,
1291
+
},
1292
+
)
1293
+
1294
+
# Access the response data
1295
+
if response.status ==200:
1296
+
result = response.json()
1297
+
print(f"Response: {result}")
1298
+
```
1299
+
1300
+
#### Example: Calling an existing endpoint with GET
asyncfor chunk in fga_client.execute_streamed_api_request(
1323
+
operation_name="StreamedListObjects",
1324
+
method="POST",
1325
+
path="/stores/{store_id}/streamed-list-objects",
1326
+
path_params={"store_id": FGA_STORE_ID},
1327
+
body={
1328
+
"type": "document",
1329
+
"relation": "viewer",
1330
+
"user": "user:anne",
1331
+
"authorization_model_id": FGA_MODEL_ID,
1332
+
},
1333
+
):
1334
+
# Each chunk has the shape {"result": {"object": "..."}} or {"error": {...}}
1335
+
if"result"in chunk:
1336
+
print(chunk["result"]["object"]) # e.g. "document:roadmap"
1337
+
```
1338
+
1339
+
#### Example: Using Path Parameters
1340
+
1341
+
Path parameters are specified in the path using `{param_name}` syntax and must all be provided explicitly via `path_params` (URL-encoded automatically):
0 commit comments