-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function to create a single endpoint definition #149
Comments
Hello, This already possible with apiBuilder. Maybe it's not clear enough in the docs that this is possible to split definitions: // getUser.ts
export default apiBuilder({
method: "get",
path: "/users/:id",
alias: "getUser",
description: "Get a user",
response: z.object({
id: z.number(),
name: z.string(),
}),
}).build(); // createUser.ts
export default apiBuilder({
method: "post",
path: "/users",
alias: "createUser",
description: "Create a user",
parameters: [{
name: 'body',
type: 'Body',
schema: z.object({
name: z.string(),
})
}],
response: z.object({
id: z.number(),
name: z.string(),
}),
}).build(); // api.ts
import getUser from './getUser';
import createUser from './createUser';
const api = new Zodios([...getUser, ...createUser]); You can check dev.to for a full example. Anyway, i think it's a good idea to also have a dedicated helper to create an individual endpoint only and this way evoid using the spread operator to combine them. Will do! |
Done! Check Release v9.2.0 |
Wow, talk about blazingly fast. Thanks 🚀 |
if not already, consider giving zodios project a star, it helps the project to be improved to make it known as it means more feedback like yours. |
We currently have an file with a bunch of route definitions. The readability really starts to get worse as the file grow, having an
makeEndpoint
method would be specially useful when we want one definition per file, e.g:The text was updated successfully, but these errors were encountered: