December 30, 2022, 10:38pm
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,
December 31, 2022, 4:04pm
You can use the
statusCode output (
see also the docs). 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).
January 1, 2023, 6:14pm
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?
January 2, 2023, 3:57pm
You can combine the output with any other, e.g.
statusCode(Created).and(stringBody). Or alternatively:
I’ve created a small example here:
tapir/StatusCodeNettyFutureServer.scala at master · softwaremill/tapir · GitHub
January 4, 2023, 8:20am
Many thanks for your help. It is clearer now. With your helps, I achieve what I wanted to do.