---
schema_version: "1"
id: 42bf5bfbc7f088662915c800775dc2e16d23f481c8661adda25e3d9123839727
title: Sharing Data Between Requests and Responses
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/pdk/1.8/policies-pdk-configure-features-share-data.md
canonical_url: https://docs.mulesoft.com/pdk/1.8/policies-pdk-configure-features-share-data
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f3acc32a86eb3af5565ee14afcc63549a57e5d644ed2b711b4be184773ef193e
description: MuleSoft Documentation Site
release: "1.8"
latest: false
---
---
product: Omni Gateway Policy Development Kit (PDK)
version: 1.8
---

# Sharing Data Between Requests and Responses

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Omni Gateway Policy Development Kit (PDK) provides the `RequestData` enum to pass data between the
request and the response.

To share a status between the request and the response functions, the request function must return a
`Flow::Continue` enum variant with a data parameter that you wish to pass to the response function.
The response function must receive the `RequestData` parameter that contains the request function’s
final status and the data parameter that was passed.

The `RequestData` enum has the following possible final status:

- `RequestData::Continue(data)`: The request function ended with `Flow::Continue(data)`.

- `RequestData::Break` : The request function ended with `Flow::Break`.

- `RequestData::Cancel`: The request function was
  [cancelled](https://docs.mulesoft.com/pdk/1.8/policies-pdk-configure-features#flow-cancellation).

If the request function ended with a `Flow::Continue` and was not cancelled by upstream policies,
the `RequestData::Continue` variant contains the value sent by the request function.

Implement this by adding an `on_response` wrapped function to the `Flow` example used in
[Stopping Request and Response Execution](https://docs.mulesoft.com/pdk/1.8/policies-pdk-configure-features-stop):

```Rust
async fn request_filter(state: RequestState) -> Flow<String> {
    let state = state.into_headers_state().await;
    let handler = state.handler();
    if handler.header("authorization").is_some() {
        Flow::Continue(state.path())
    } else {
        Flow::Break(
            Response::new(401)
                .with_headers(vec![(
                    "WWW-Authenticate".to_string(),
                    "Bearer realm=\"oauth2\"".to_string(),
                )])
                .with_body(r#"{ "error": "token was not present"}"#),
        )
    }
}

async fn response_filter(state: ResponseState, request_data: RequestData<String>) {
    // Handle only completed requests
    if let RequestData::Continue(path) = request_data else {
        return;
    };

    let state = state.into_headers_state().await;
    logger::info!("Path: {path}, Status: {}", state.status_code());
}
```

## See Also

- [Implementing Your Custom Policy Features in Rust](https://docs.mulesoft.com/pdk/1.8/policies-pdk-configure-features)

- [Rate Limiting Requests](https://docs.mulesoft.com/pdk/1.8/policies-pdk-configure-features-rate-limiting)
