Skip to content

Commit cba8f6a

Browse files
committed
docs: add docs to readme for header usage
1 parent 7086be5 commit cba8f6a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,67 @@ public class Example {
236236
}
237237
```
238238

239+
### Custom Headers
240+
241+
#### Default Headers
242+
243+
You can set default headers to be sent with every request by using the `defaultHeaders` property of the `ClientConfiguration` class.
244+
245+
```java
246+
import com.fasterxml.jackson.databind.ObjectMapper;
247+
import dev.openfga.sdk.api.client.OpenFgaClient;
248+
import dev.openfga.sdk.api.configuration.ClientConfiguration;
249+
250+
import java.net.http.HttpClient;
251+
import java.util.Map;
252+
253+
public class Example {
254+
public static void main(String[] args) throws Exception {
255+
var config = new ClientConfiguration()
256+
.apiUrl(System.getenv("FGA_API_URL"))
257+
.storeId(System.getenv("FGA_STORE_ID"))
258+
.authorizationModelId(System.getenv("FGA_MODEL_ID"))
259+
.defaultHeaders(Map.of(
260+
"X-Custom-Header", "default-value",
261+
"X-Request-Source", "my-app"
262+
));
263+
264+
var fgaClient = new OpenFgaClient(config);
265+
}
266+
}
267+
```
268+
269+
#### Per-request Headers
270+
271+
You can set custom headers to be sent with a specific request by using the `additionalHeaders` property of the options classes (e.g. `ClientReadOptions`, `ClientWriteOptions`, etc.).
272+
273+
```java
274+
import com.fasterxml.jackson.databind.ObjectMapper;
275+
import dev.openfga.sdk.api.client.OpenFgaClient;
276+
import dev.openfga.sdk.api.configuration.ClientConfiguration;
277+
import java.net.http.HttpClient;
278+
279+
public class Example {
280+
public static void main(String[] args) throws Exception {
281+
var config = new ClientConfiguration()
282+
.apiUrl(System.getenv("FGA_API_URL"))
283+
.storeId(System.getenv("FGA_STORE_ID"))
284+
.authorizationModelId(System.getenv("FGA_MODEL_ID"))
285+
.defaultHeaders(Map.of(
286+
"X-Custom-Header", "default-value",
287+
"X-Request-Source", "my-app"
288+
));
289+
290+
var fgaClient = new OpenFgaClient(config);
291+
var options = new ClientReadOptions()
292+
.additionalHeaders(Map.of(
293+
"X-Request-Id", "123e4567-e89b-12d3-a456-426614174000",
294+
"X-Custom-Header", "overridden-value" // this will override the default value for this request only
295+
)
296+
);
297+
}
298+
}
299+
```
239300

240301
### Get your Store ID
241302

0 commit comments

Comments
 (0)