Fabszn
December 30, 2022, 10:38pm
1
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,
adamw
December 31, 2022, 4:04pm
2
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).
Fabszn
January 1, 2023, 6:14pm
3
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?
adamw
January 2, 2023, 3:57pm
4
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
Fabszn
January 4, 2023, 8:20am
5
Hi Adam,
Many thanks for your help. It is clearer now. With your helps, I achieve what I wanted to do.
Kind regards
1 Like