|
| 1 | +# Streamed List Objects example for OpenFGA's Java SDK |
| 2 | + |
| 3 | +This example demonstrates working with the `POST` `/stores/:id/streamed-list-objects` endpoint in OpenFGA using the Java SDK. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +If you do not already have an OpenFGA instance running, you can start one using the following command: |
| 8 | + |
| 9 | +```bash |
| 10 | +make run-openfga |
| 11 | +``` |
| 12 | + |
| 13 | +Or directly with docker: |
| 14 | + |
| 15 | +```bash |
| 16 | +docker run -d -p 8080:8080 openfga/openfga run |
| 17 | +``` |
| 18 | + |
| 19 | +## Configure the example |
| 20 | + |
| 21 | +You may need to configure the example for your environment by setting environment variables: |
| 22 | + |
| 23 | +```bash |
| 24 | +export FGA_API_URL=http://localhost:8080 |
| 25 | +``` |
| 26 | + |
| 27 | +Optional authentication configuration: |
| 28 | +```bash |
| 29 | +export FGA_CLIENT_ID=your-client-id |
| 30 | +export FGA_CLIENT_SECRET=your-client-secret |
| 31 | +export FGA_API_AUDIENCE=your-api-audience |
| 32 | +export FGA_API_TOKEN_ISSUER=your-token-issuer |
| 33 | +``` |
| 34 | + |
| 35 | +## Running the example |
| 36 | + |
| 37 | +Build the project: |
| 38 | + |
| 39 | +```bash |
| 40 | +make build |
| 41 | +``` |
| 42 | + |
| 43 | +Run the example: |
| 44 | + |
| 45 | +```bash |
| 46 | +make run |
| 47 | +``` |
| 48 | + |
| 49 | +This will: |
| 50 | +1. Create a temporary store |
| 51 | +2. Create an authorization model |
| 52 | +3. Write 100 mock tuples |
| 53 | +4. Stream all objects using the `streamedListObjects` API |
| 54 | +5. Display each object as it's received |
| 55 | +6. Clean up the temporary store |
| 56 | + |
| 57 | +## What to expect |
| 58 | + |
| 59 | +The example will output each object as it's streamed from the server: |
| 60 | + |
| 61 | +``` |
| 62 | +Created temporary store (01HXXX...) |
| 63 | +Created temporary authorization model (01GXXX...) |
| 64 | +Writing 100 mock tuples to store. |
| 65 | +Listing objects using streaming endpoint: |
| 66 | + document:0 |
| 67 | + document:1 |
| 68 | + document:2 |
| 69 | + ... |
| 70 | + document:99 |
| 71 | +API returned 100 objects. |
| 72 | +Deleted temporary store (01HXXX...) |
| 73 | +Finished. |
| 74 | +``` |
| 75 | + |
| 76 | +## Note |
| 77 | + |
| 78 | +The streaming API is particularly useful when dealing with large result sets, as it: |
| 79 | +- Reduces memory usage by processing objects one at a time |
| 80 | +- Provides faster time-to-first-result |
| 81 | +- Allows for real-time processing of results |
| 82 | +- Is only limited by execution timeout rather than result set size |
0 commit comments