# Set status code to 201 in response

**URL:** <https://softwaremill.community/t/set-status-code-to-201-in-response/59>\
**Category:** tapir\
**Created:** [December 30, 2022, 10:38pm UTC](https://softwaremill.community/t/set-status-code-to-201-in-response/59 "2022-12-30T22:38:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabszn](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/fabszn/32/55_2.png) [@Fabszn](https://softwaremill.community/u/Fabszn)\
**Post date:** [December 30, 2022, 10:38pm UTC](https://softwaremill.community/t/set-status-code-to-201-in-response/59/1 "2022-12-30T22:38:56Z")

</div>

Hi all,

I’m wondering how I can set status code to 201 for response. I dive into documentation and i didn’t found the way to achieve it.

I would like answer by Htp 201 with JsonBody payload. I sppose there is an other way than oneOfVariant ?

Many thanks for your help,

Kind regards,

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [December 31, 2022, 4:04pm UTC](https://softwaremill.community/t/set-status-code-to-201-in-response/59/2 "2022-12-31T16:04:28Z")

</div>

You can use the `statusCode` output ([see also the docs](https://tapir.softwaremill.com/en/latest/endpoint/ios.html#status-codes)). There are two variants - either a static status code (`statusCode(StatusCode.Created)`). Or a dynamic one, which is set by the server logic (`statusCode` without parameters).

---

<div class="post-metadata">

**Author:** ![Fabszn](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/fabszn/32/55_2.png) [@Fabszn](https://softwaremill.community/u/Fabszn)\
**Post date:** [January 1, 2023, 6:14pm UTC](https://softwaremill.community/t/set-status-code-to-201-in-response/59/3 "2023-01-01T18:14:01Z")

</div>

Hi!

Many thanks for your answer. I wish you happy new year 🤗.

From my comprehension, in case of using statusCode(…) that means that I can’t put nothing in response body?

Also, by using onOf Variant I must used with error canal and in my case created status code is not error case (if I am not’wrong)

You know what I mean?

May be do you have one example?

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [January 2, 2023, 3:57pm UTC](https://softwaremill.community/t/set-status-code-to-201-in-response/59/4 "2023-01-02T15:57:27Z")

</div>

You can combine the output with any other, e.g. `statusCode(Created).and(stringBody)`. Or alternatively: `endpoint.out(statusCode).out(stringBody)`.

I’ve created a small example here: [tapir/StatusCodeNettyFutureServer.scala at master · softwaremill/tapir · GitHub](https://github.com/softwaremill/tapir/blob/master/examples/src/main/scala/sttp/tapir/examples/status_code/StatusCodeNettyFutureServer.scala)

---

<div class="post-metadata">

**Author:** ![Fabszn](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/fabszn/32/55_2.png) [@Fabszn](https://softwaremill.community/u/Fabszn)\
**Post date:** [January 4, 2023, 8:20am UTC](https://softwaremill.community/t/set-status-code-to-201-in-response/59/5 "2023-01-04T08:20:20Z")

</div>

Hi Adam,

Many thanks for your help. It is clearer now. With your helps, I achieve what I wanted to do.

Kind regards
