> For the complete documentation index, see [llms.txt](https://marblejs.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://marblejs.gitbook.io/docs/http/output.md).

# Output

## Building your own output effect

Using `HttpOutputEffect` you can grab an outgoing Effect response and map it into different one, modifying outgoing data on demand.

```haskell
type Out = {
  request: HttpRequest;
  headers: HttpHeaders;
  status: HttpStatus;
  body: any;
};

HttpOutputEffect :: Observable<Out> -> Observable<Out>
```

`HttpOutputEffect` allows you to grab the outgoing response together with corresponding initial request.  The output effect works similar to the HttpMiddlewareEffect, but in that case for outgoing responses. Let's build a simple response compression middleware.

{% tabs %}
{% tab title="output.effect.ts" %}

```typescript
import { HttpOutputEffect } from '@marblejs/http';
import { map } from 'rxjs/operators';
import * as zlib from 'zlib';

const output$: HttpOutputEffect = res$ =>
  res$.pipe(
    map(({ request, headers, body, status }) =>  {
      switch(request.headers['accept-encoding']) {
        case 'br':
          return ({
            request,
            status,
            headers: { ...headers, 'Content-Encoding': 'br' },
            body: body.pipe(zlib.createBrotliDecompress()),
          });
        case 'gzip':
          return ({
            request,
            status,
            headers: { ...headers, 'Content-Encoding': 'gzip' },
            body: body.pipe(zlib.createGunzip()),
          });
        case 'deflate':
          return ({
            request,
            status,
            headers: { ...headers, 'Content-Encoding': 'deflate' },
            body: body.pipe(zlib.createInflate()),
          });
        default:
          return { status, headers, body, request };
      }
    }),
  );
```

{% endtab %}
{% endtabs %}

To connect the output effect, all you need to do is to attach it to `output$` property in `httpListener` config object.

```typescript
import { httpListener } from '@marblejs/http';
import { output$ } from './output.effect';

export const listener = httpListener({
  middlewares: [ ... ],
  effects: [ ... ],
  output$, // 👈
});
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://marblejs.gitbook.io/docs/http/output.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
