https://kotlinlang.org logo
#kobweb
Title
# kobweb
f

Funyinoluwa Kashimawo

10/11/2023, 5:42 PM
Hi @David Herman, how do I include path parameters in api routes?
d

David Herman

10/11/2023, 5:56 PM
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

Funyinoluwa Kashimawo

10/11/2023, 6:18 PM
Not the query parameters, path parameters like
/api/posts/{id}/comments
d

David Herman

10/11/2023, 6:18 PM
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

Funyinoluwa Kashimawo

10/11/2023, 7:07 PM
Thanks, yeah I guessed so too.
d

David Herman

10/11/2023, 8:04 PM
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

Funyinoluwa Kashimawo

10/12/2023, 12:59 AM
Thanks for clearing that. I decided to use a query param instead. 👍
d

David Herman

10/12/2023, 1:11 AM
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
4 Views