<commit_before># Request headers

## Default request headers

It is possible to change the request headers for every request made by the Alcaeus
client.

Especially useful for setting authentication headers, the example below show
how the `Accept` header can be changed so that Turtle has higher priority over
JSON-LD.

{% runkit %}
const { Hydra } = require("alcaeus@{{ book.version }}");

Hydra.defaultHeaders = {
  Accept: 'text/turtle, application/ld+json'
}

const rep = await client.loadResource('https://sources.test.wikibus.org/')

rep.xhr.headers.get('content-type');
{% endrunkit %}

Alternatively, a function can be used to dynamically build the default headers
before each request.

`Hydra.defaultHeaders = () => { /* headers */ }`

## Setting headers for a single request

Individual calls to `Hydra.loadResource` or `IOperation#invoke` also accept a
set of headers to be used for the following request.

```typescript
import { Hydra } from 'alcaeus'<commit_msg>docs: fix runkit snippet<commit_after># Request headers

## Default request headers

It is possible to change the request headers for every request made by the Alcaeus
client.

Especially useful for setting authentication headers, the example below show
how the `Accept` header can be changed so that Turtle has higher priority over
JSON-LD.

{% runkit %}
const { Hydra } = require("alcaeus@{{ book.version }}");

Hydra.defaultHeaders = {
  Accept: 'text/turtle, application/ld+json'
}

const rep = await Hydra.loadResource('https://sources.test.wikibus.org/')

rep.xhr.headers.get('content-type');
{% endrunkit %}

Alternatively, a function can be used to dynamically build the default headers
before each request.

`Hydra.defaultHeaders = () => { /* headers */ }`

## Setting headers for a single request

Individual calls to `Hydra.loadResource` or `IOperation#invoke` also accept a
set of headers to be used for the following request.

```typescript
import { Hydra } from 'alcaeus'
{'fraction_non_alphanumeric': 0.10153061224489796, 'fraction_numerical': 0.0, 'mean_word_length': 4.733918128654971, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2470333', 'n_tokens_mistral': 591, 'n_tokens_neox': 556, 'n_words': 220}