---
schema_version: "1"
id: cb7e83d60b6ef102d29b76c06ec994a3cc69421227300a4838b3aceddc11e6d0
title: Configuring the Response Headers and Status Code
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/apikit/latest/configure-headers4-task.md
canonical_url: https://docs.mulesoft.com/apikit/latest/configure-headers4-task
source_site: docs.mulesoft.com
content_type: documentation
content_hash: c12dc2ddaf041141676e953fe4d1c6be734e2efae4624d5ba272d42681582552
description: MuleSoft Documentation Site
release: 4.x
latest: true
---
---
product: APIkit
version: 4.x
is-latest-version: true
---

# Configuring the Response Headers and Status Code

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

Map APIkit for REST outbound headers and HTTP status values to variables the HTTP Listener writes
into each response. Configure `outboundHeadersMapName` and `httpStatusVarName` on `apikit:config` so
flows set `vars.outboundHeaders` and `vars.httpStatus` consistently across success and error paths.
The steps align listener response blocks with those variable names.

## Configure Variable Names

You can configure the default variables that the HTTP listener searches for by configuring these
properties in **APIkit Router**:

- `outboundHeadersMapName`

  Name of the variable that contains a headers map added in the response (`outboundHeaders` by
  default)

- `httpStatusVarName`

  Name of the variable that stores the status code to set in the response (`httpStatus` by default)

**APIkit Router** creates both variables and facilitates including custom HTTP headers and status
codes in the response.

```xml
<apikit:config  name="api-config"
                api="api.raml"
                outboundHeadersMapName="outboundHeaders"
                httpStatusVarName="httpStatus"/>
```

To modify the default names of these variables, update the default HTTP listener configuration to
align the variable names and the configuration.

```xml
<http:listener config-ref="api-httpListenerConfig" path="/api/*">
    <http:response
        statusCode="#[vars.httpStatus default 200]">
        <http:headers>#[vars.outboundHeaders default {}]</http:headers>
    </http:response>
    <http:error-response
        statusCode="#[vars.httpStatus default 500]">
        <http:body>#[payload]</http:body>
        <http:headers>#[vars.outboundHeaders default {}]</http:headers>
    </http:error-response>
</http:listener>
```

## Add a Header to a Response

Put the header to add in the `outboundHeaders` map, as shown in the following example:

```xml
<set-variable
    value='#[vars.outboundHeaders default {} ++ {newHeaderName: "Header value"}]'
    variableName="outboundHeaders"/>
```

## Set the Status Code of a Response

Use the following example as a reference to assign a specific value to the `httpStatus` variable:

```xml
<set-variable
    value="201"
    variableName="httpStatus"/>
```

## See Also

- [Sending HTTP responses when configuring HTTP listener source in Mule 4](https://docs.mulesoft.com/http-connector/1.7/http-listener-ref#sending-http-responses)
