-
Hi! I was looking for something that enforced zod types to my input body/query params and automatically caught exceptions thrown from my async handlers and i found this. Looks awesome and at first glance it functions well. After diving a bit deeper though i've run into some problems:
1. Array output error2. DependsOnMethodconst post = defaultEndpointsFactory.build({
description: 'Create todo',
method: 'post', // explicitly have to say that it is a post method
input: CreateTodoInput,
output: CreateTodoOutput,
handler: async ({ input: todo}) => {
todos.push({ ...todo, id })
id++;
return {...todo, id }
},
})
export default new DependsOnMethod({
post,
}) Most of these questions probably have a simple answer, and this issue is not about the problem themselves (if any) but the lack of documentation. Not trying to sound like a jerk here, i'm just happy i found this. Great work 👍 |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
Hello @linde12 . Thank you for your feedback. I am happy to answer your questions in order.
You can find the complete answer here: #73 const myRouting: Routing = {
users: {
':id': myEndpoint // <— connected to /users/:id
}
}; And in order to obtain the value of
Shortly: you should pass the array to an object property. // instead of
return [1,2,3];
// do this
return {
myData: [1,2,3]
} This is an intentional limitation: the output of the
That should be easy. Please try this: const myEndpoint = myEndpointsFactory.build({
method: 'get',
input: z.object({}),
...
}); So just use an empty object schema. The object being validated as
Yes. This is to make it possible to implement many-to-many relationships between the available route methods and the supported handler methods. Here is an example of such case: // example of different I/O schemas for /v1/user
const routing: Routing = {
v1: {
user: new DependsOnMethod({
get: myEndpointA, // GET —> handler for GET and DELETE
delete: myEndpointA, // DELETE —> handler for GET and DELETE
post: myEndpointB, // POST —> handler for POST and PATCH
patch: myEndpointB, // PATCH —> handler for POST and PATCH
})
}
};
You're right. There is no such example. Currently Please let me know if I managed to provide you with required answers or something need to be additionally clarified. |
Beta Was this translation helpful? Give feedback.
-
Hi @RobinTail ! Thank you for your in-depth reply! I am clear on all things except:
I think i was a bit unclear in my question, but i'm wondering if i still have to set the |
Beta Was this translation helpful? Give feedback.
-
Hello @linde12 .
Yes, you have to. I hope I managed to clarify this topic for you. |
Beta Was this translation helpful? Give feedback.
-
Hello @linde12 , I made a PR on the new config option that I believe will help you to achieve the desired behavior: including The feature will be released in version 2.8.0. The issue will be converted to discussion. |
Beta Was this translation helpful? Give feedback.
-
The feature has been released in version 2.8.0 🎉 |
Beta Was this translation helpful? Give feedback.
-
I came to conclusion that |
Beta Was this translation helpful? Give feedback.
-
Now supporting array response: #361 (comment) |
Beta Was this translation helpful? Give feedback.
Hello @linde12 .
Thank you for your feedback. I am happy to answer your questions in order.
You can find the complete answer here: #73
Basically you should do this:
And in order to obtain the value of
:id
you need aparamsProviderMiddleware
. You will find an example at the link mentioned above.Shortly: you should pass the array to an object pro…