Type safety for api routes
Answered
Shaurya posted this in #help-forum
ShauryaOP
how do I make the api routes type safe? do I just create my types and set the type on the body and request and do the same on the received json and posting body or is there some other built in way in nextjs?
Answered by Asian black bear
Next has nothing built-in for that, you'd have to manually use a validation library like zod or Effect's schema module to assert the types during runtime. Alternatively, using sophisticated code generators could be an option as well.
1 Reply
Asian black bear
Next has nothing built-in for that, you'd have to manually use a validation library like zod or Effect's schema module to assert the types during runtime. Alternatively, using sophisticated code generators could be an option as well.
Answer