Skip to content

Commit 8d4937d

Browse files
authored
Add Global Headers guide (#76)
1 parent 0097332 commit 8d4937d

File tree

1 file changed

+95
-2
lines changed

1 file changed

+95
-2
lines changed

fern/products/sdks/guides/configure-global-headers.mdx

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,99 @@ title: Configure Global Headers
33
description: Guide to configuring global headers in your SDKs.
44
---
55

6-
Learn how to configure global headers for all requests made by your SDKs.
6+
Your API may leverage certain headers for every endpoint or most endpoints.
7+
These are called **global headers**.
78

8-
<Warning>Docs are coming soon for this page.<br/><br/>Please [book a demo](https://buildwithfern.com/book-demo) or [reach out to us](https://buildwithfern.com/book-demo) to get set up with this feature. </Warning>
9+
## How it works for SDK users
10+
11+
Once you configure a global header (either automatically detected or manually
12+
specified), Fern generates an SDK that accepts this as a constructor parameter.
13+
Users can then provide the value once, and the generated SDK automatically
14+
includes the header in all their API calls:
15+
16+
```python
17+
import os
18+
19+
class Client:
20+
21+
def __init__(self, *, apiKey: str):
22+
```
23+
24+
## Specifying global headers
25+
26+
Fern automatically identifies headers that are used in every request, or the
27+
majority of requests, and marks them as global. You can manually configure additional
28+
global headers in either `api.yml` (Fern Definition) or `openapi.yml`.
29+
30+
<AccordionGroup>
31+
<Accordion title="Fern Definition">
32+
33+
To specify headers that are meant to be included on every request:
34+
35+
<CodeBlock title="api.yml">
36+
```yaml {3}
37+
name: api
38+
headers:
39+
X-App-Id: string
40+
```
41+
</CodeBlock>
42+
43+
### Global path parameters
44+
You can also specify path parameters that are meant to be included on every request:
45+
46+
<CodeBlock title="api.yml">
47+
```yaml
48+
name: api
49+
base-path: /{userId}/{orgId}
50+
path-parameters:
51+
userId: string
52+
orgId: string
53+
```
54+
</CodeBlock>
55+
56+
#### Overriding the base path
57+
58+
If you have certain endpoints that do not live at the configured `base-path`, you can
59+
override the `base-path` at the endpoint level.
60+
61+
```yml imdb.yml {5}
62+
service:
63+
endpoints:
64+
getMovie:
65+
method: POST
66+
base-path: "override/{arg}"
67+
path: "movies/{movieId}"
68+
path-parameters:
69+
arg: string
70+
```
71+
72+
<Note>
73+
You cannot yet specify query parameters that are meant to be included on every request.
74+
If you'd like to see this feature, please upvote [this issue](https://github.com/fern-api/fern/issues/2930).
75+
</Note>
76+
77+
</Accordion>
78+
<Accordion title="OpenAPI">
79+
80+
Use the `x-fern-global-headers` extension to label additional headers as global
81+
or to alias the names of global headers:
82+
83+
```yaml title="openapi.yml"
84+
x-fern-global-headers:
85+
- header: custom_api_key
86+
name: api_key
87+
- header: userpool_id
88+
optional: true
89+
```
90+
91+
This configuration yields the following client:
92+
93+
```python
94+
import os
95+
96+
class Client:
97+
98+
def __init__(self, *, apiKey: str, userpoolId: typing.Optional[str])
99+
```
100+
</Accordion>
101+
</AccordionGroup>

0 commit comments

Comments
 (0)