Hi <@U02AB5P2XU6>, how do I include path parameter...
# kobweb
f
Hi @David Herman, how do I include path parameters in api routes?
d
API routes pass parameters into the
ctx.req.params
object: https://github.com/varabyte/kobweb#define-api-routes
I'm assuming that's what you're talking about? The
?a=1&b=xyz
stuff?
f
Not the query parameters, path parameters like
/api/posts/{id}/comments
d
In that case you'll have to parse them on the frontend and pass them in yourself
Oh wait
I see what you're saying
In a meeting, so AFK, but I don't think path parameters work for API routes
f
Thanks, yeah I guessed so too.
d
Keep in mind that a reason that url path parameters are supported is because it makes for cleaner urls to share. Whereas API paths are supposed to be invisible to the end user, so arguably the extra complexity to support it isn't necessary there.
f
Thanks for clearing that. I decided to use a query param instead. 👍
d
Sounds good!
If data starts to get fancy, I also recommend using serialization plus a body payload (which I do in the
kobweb create examples/todo
example)
👍 1