# How to change status code of headers of response?

**URL:** <https://forum.serverless.com/t/how-to-change-status-code-of-headers-of-response/5878>\
**Category:** Serverless Framework\
**Tags:** lambda\
**Created:** [September 19, 2018, 2:37pm UTC](https://forum.serverless.com/t/how-to-change-status-code-of-headers-of-response/5878 "2018-09-19T14:37:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![foretribe](https://avatars.discourse-cdn.com/v4/letter/f/3da27b/32.png) [@foretribe](https://forum.serverless.com/u/foretribe)\
**Post date:** [September 19, 2018, 2:37pm UTC](https://forum.serverless.com/t/how-to-change-status-code-of-headers-of-response/5878/1 "2018-09-19T14:37:54Z")

</div>

I want to response personal defined statuscode and some headers.  
But I find even I change the status code to 201 the status code is still 200. and my defined header is not in headers.

my handler like:

```auto
function createResponse(status, header, body) {
  return {
    headers: Object.assign(header, {
      'Access-Control-Allow-Origin': '*',
      'Content-Type': 'application/json;charset=utf-8'
    }),
    statusCode: status,
    body: JSON.stringify(body)
  }
}
export const hello = async (event, context, cb) => { 
  const rep = {
      message: 'v1.0',
      event: event
  };
  cb(null, createResponse(201, {}, rep));
  return;
};

```

How to check to correct code can change status code and response header?

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [September 20, 2018, 6:32am UTC](https://forum.serverless.com/t/how-to-change-status-code-of-headers-of-response/5878/2 "2018-09-20T06:32:43Z")

</div>

Try returning the result from your `createResponse()` call instead of using the callback parameter as it’s not officially part of the `async` handler syntax.

```auto
function createResponse(status, header, body) {
  return {
    headers: Object.assign(header, {
      'Access-Control-Allow-Origin': '*',
      'Content-Type': 'application/json;charset=utf-8'
    }),
    statusCode: status,
    body: JSON.stringify(body)
  }
}
export const hello = async (event, context) => { 
  const rep = {
      message: 'v1.0',
      event: event
  };
  return createResponse(201, {}, rep);
};

```
