Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- [Basic Configuration](#basic-configuration)
- [Authentication](#authentication)
- [API Token Authentication](#api-token-authentication)
- [Custom Headers](#custom-headers)
3. [API Reference](#-api-reference)
4. [Resource Managers](#-resource-managers)
- [`.collection()`](#collectionresource)
Expand Down Expand Up @@ -118,6 +119,50 @@ const client = strapi({
});
```

#### Custom Headers

You can configure custom headers to be included with every request made by the client:

```typescript
const client = strapi({
baseURL: 'http://localhost:1337/api',
auth: 'your-api-token-here',
headers: {
'X-Custom-Header': 'value',
'Accept-Language': 'en-US',
},
});
```

**Header Precedence:**

- Custom headers specified in the client configuration are applied to all requests
- Authentication headers (e.g., `Authorization` from API tokens) take precedence over custom headers
- Headers specified in individual requests (e.g., in `fetch()` calls) take precedence over both custom and authentication headers

**Example: Using Custom Headers**

```typescript
// Initialize client with custom headers
const client = strapi({
baseURL: 'http://localhost:1337/api',
headers: {
'X-Request-ID': '12345',
'Accept-Language': 'en-US',
},
});

// Headers will be included in all requests
const articles = await client.collection('articles').find();

// Override headers for a specific request
const article = await client.fetch('/articles/1', {
headers: {
'Accept-Language': 'fr-FR', // This will override the client-level header
},
});
```

## 📚 API Reference

The Strapi client library instance provides key properties and utility methods for content and API interaction:
Expand Down