> For the complete documentation index, see [llms.txt](https://docs.fact-finder.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fact-finder.com/webcomponents-overview/web-components-4.x./api/more-features/middleware.md).

# Middleware

Transform FactFinder requests and responses before components receive data.

## Documentation

### Middleware

Starting with version `1.2.13`, FactFinder Web Components supports middleware.

Middleware modules manipulate data exchanged between FactFinder and Web Components. Register modules through Web Components or JavaScript.

**FactFinder Web Components approach**

Place `ff-middleware` directly inside `ff-communication`. It contains all configured modules.

```html
<ff-communication url="..."
                  version="..."
                  api="..."
                  channel="...">
    <ff-middleware></ff-middleware>
</ff-communication>
```

`ff-middleware` must be an immediate child of `ff-communication`. Otherwise, module registration causes an application error.

**JavaScript approach**

Attach an event handler to `ffReady`. Register modules with `use()` in the relevant middleware namespace.

```javascript
window.addEventListener("ffReady", function (event) {
    const factfinder = event.factfinder;
    factfinder.middleware.response.use(module);
});
```

This example registers response middleware. It runs after FactFinder responds and before `ResultDispatcher` notifies its listeners.

**Available modules**

All modules support Web Components and JavaScript registration. When using Web Components, place every module directly inside `ff-middleware`.

**Response**

Response middleware modifies response data. It is available through `factfinder.middleware.response`. Register modules with `factfinder.middleware.response.use()`.

**MultiAttributeParsing**

`MultiAttributeParsing` parses multi-attribute fields into accessible JavaScript objects. FactFinder returns multi-attribute fields as strings:

```
|Size=M|Material=Cotton|Material=Synthetic fibres|Weight~~g=80|Recommended use=Leisure
```

The module converts that value to:

```json
{
    "Size": [
        { "value": "M", "unit": undefined }
    ],
    "Material": [
        { "value": "Cotton", "unit": undefined },
        { "value": "Synthetic fibres", "unit": undefined }
    ],
    "Weight": [
        { "value": "80", "unit": "g" }
    ],
    "Recommended use": [
        { "value": "Leisure", "unit": undefined }
    ]
}
```

Use non-empty Mustache list sections to render parsed fields. Mustache supports spaces in property names.

```html
<ff-record-list>
    <ff-record>
        <img data-image="{{record.ImageName}}"
             data-image-onerror="../img_not_found.gif">

        <div>
            <div>{{record.Title}}</div>
            <div>Price: <strong>{{record.Price}}</strong></div>

            <div>Recommended use:
                {{#record.MultiFilter.Recommended use}}<span>{{value}}</span>{{/record.MultiFilter.Recommended use}}
            </div>
            <div>Material:
                {{#record.MultiFilter.Material}}<span>{{value}}</span>{{/record.MultiFilter.Material}}
            </div>
            <div>Weight:
                {{#record.MultiFilter.Weight}}<span>{{value}} {{unit}}</span>{{/record.MultiFilter.Properties}}
            </div>
        </div>
    </ff-record>
</ff-record-list>
```

Register `MultiAttributeParsing` with Web Components:

```html
<ff-communication>
    <ff-middleware>
        <ff-multi-attribute-parsing
                src-property="MultiFilter"
                store-in-property="MultiFilter"
                keep-original-in-property="OriginalMultiFilter"
                entry-separator="|"
                key-value-separator="="
        ></ff-multi-attribute-parsing>
    </ff-middleware>
</ff-communication>
```

Or register it with JavaScript:

```javascript
window.addEventListener("ffReady", function (event) {
    const factfinder = event.factfinder;
    factfinder.middleware.response.use(factfinder.middleware.response.MultiAttributeParsing({
        srcProperty: "MultiFilter",
        storeInProperty: "MultiFilter",
        keepOriginalInProperty: "OriginalMultiFilter",
        entrySeparator: "|",
        keyValueSeparator: "="
    }));
});
```

See the API reference for all configuration options.

**ProductTeaserCampaignProcessor**

This module inserts teaser feedback text campaigns into `searchResult.records`. It inserts them at their configured positions.

Each teaser produces an `ff-record` with an `is-teaser` attribute. Its inner HTML contains the text configured in FactFinder.

Configure it with Web Components:

```html
<ff-communication>
    <ff-middleware>
        <ff-product-teaser-campaign-processor></ff-product-teaser-campaign-processor>
    </ff-middleware>
</ff-communication>
```

Or configure it with JavaScript:

```javascript
window.addEventListener("ffReady", function (event) {
    const factfinder = event.factfinder;
    factfinder.middleware.response.use(
        factfinder.middleware.response.ProductTeaserCampaignProcessor()
    );
});
```

## API code

### `ff-middleware`

### `ff-multi-attribute-parsing`

**Properties**

<details>

<summary>Properties</summary>

| Name                                             | Description                                           |
| ------------------------------------------------ | ----------------------------------------------------- |
| **src-property** (String, required)              | Multi-attribute field name returned by FactFinder.    |
| **store-in-property** (String, required)         | Property where the parsed object is stored.           |
| **keep-original-in-property** (String, optional) | Property where the original unparsed value is stored. |
| **entry-separator** (String, default: `"ǀ"`)     | Character separating key-value pairs in FactFinder.   |
| **key-value-separator** (String, default: `"="`) | Character separating each key from its value.         |

</details>

### `ff-product-teaser-campaign-processor`

This element has no properties.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.fact-finder.com/webcomponents-overview/web-components-4.x./api/more-features/middleware.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
