Body & Query for PATCH/PUT methods #2097
Answered
by
RobinTail
shubham941122
asked this question in
Q&A
-
Hi, is there a provision to take query, path, headers and requestBody as input for these methods. inputSources: {
get: ['query', 'params', 'headers'],
post: ['body', 'params', 'query', 'headers'],
put: ['body', 'query', 'params', 'headers'],
patch: ['body', 'query', 'params', 'headers'],
delete: ['query', 'params', 'headers'],
}, Endpoint: export const updateUserEndpoint = taggedEndpointsFactory.addMiddleware(methodProviderMiddleware).build({
method: 'post',
tag: 'users',
shortDescription: 'Updates an user by its ID.',
description: 'Example user retrieval endpoint.',
input: z
.object({
...headersSchema.shape,
id: z
.string()
.trim()
.regex(/\d+/)
.transform((id) => parseInt(id, 10))
.describe('a numeric string containing the id of the user'),
name: z.string().min(1),
serviceInfo: z.object({
serviceBandwidth: z.string().trim().describe('a string containing the serviceBandwidth'),
serviceType: z.string().trim().describe('a string containing the serviceType'),
}),
})
.example({
id: '12',
name: 'John Doe',
serviceInfo: {
serviceBandwidth: '10GB',
serviceType: 'Fiber',
},
}),
output: z
.object({
name: z.string(),
createdAt: ez.dateOut(),
})
.example({
name: 'John Doe',
createdAt: new Date('2021-12-31'),
}),
handler: async ({ input: { id, name }, options: { method }, logger }) => {
logger.debug(`Requested id: ${id}, method ${method}, Name to set: ${name}`);
if (id > 100) throw createHttpError(404, 'User not found');
throw createHttpError(500, 'Not implemented yet!');
},
}); With above config, i am not able to achieve the desired behaviour. Any suggestions? |
Beta Was this translation helpful? Give feedback.
Answered by
RobinTail
Oct 14, 2024
Replies: 1 comment 3 replies
-
|
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
RobinTail
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
options
), but path params ✅ — useparams
body
✅