-
Hello. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hello @vedun , Thank you for the question. To obtain the value of URL param you will also require a middleware that will provide your endpoint handler with such option. Here is a complete example for you: const paramsProviderMiddleware = createMiddleware({
input: z.object({}),
middleware: async ({request}) => ({
params: request.params
})
});
const endpointsFactory = new EndpointsFactory();
const myEndpoint = endpointsFactory
.addMiddleware(paramsProviderMiddleware)
.build({
methods: ['get'],
input: z.object({}),
output: z.object({}),
handler: async ({options, logger}) => {
logger.debug('id', options.params.id); // the value of :id in the path
return {};
}
});
const myRouting: Routing = {
user: {
':id': myEndpoint // <— /user/:id
}
};
createServer(config, myRouting); Please let me know how it works for you. |
Beta Was this translation helpful? Give feedback.
-
@RobinTail thank you for your answer. Probably it is good solution for me. |
Beta Was this translation helpful? Give feedback.
-
@vedun , starting version 3.1.x you no longer need |
Beta Was this translation helpful? Give feedback.
Hello @vedun ,
Thank you for the question.
The path is being constructed by concatenation of properties defined in
Routing
object.So you just need to have an
:id
property inside ofuser
. In order to do that you need to wrap it in quotes.To obtain the value of URL param you will also require a middleware that will provide your endpoint handler with such option.
Here is a complete example for you: