How to properly use Transformer/Serializer together with response.created() in AdonisJS? #5096
Unanswered
matheusroberson
asked this question in
Help
Replies: 1 comment
-
|
The response helpers are not type-safe right now. Therefore, you will have to set the status code separately and return a response using the serialize method. response.status(201)
return serialize(UserTransform.transform(user)) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to structure my API responses using a transformer/serializer pattern, but I'm running into an issue when combining it with the HTTP response methods.
My goal is to return something like:
However, I can't seem to properly use
serializetogether withresponse. It feels like I have to choose between:response.created()to control the HTTP responsetransform/serializeto format the outputBut not both together in a clean way.
What I expected
Ideally, I want to:
Current problem
When I try to combine them, it either:
responsehelperQuestions
serializeis supposed to be used?Any guidance or best practices would be appreciated.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions