sholladay / pogo

Server framework for Deno

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynamic routes

victmo opened this issue · comments

Is there a way to support dynamic routes?

Something like:

server.route({
  method: 'GET',
  path: '/v2/users/{userId}/books',
  handler: (req, h) => {...}
})

Not at the moment, but this is absolutely an important feature that I want to have.

We need to port hapijs/call to Deno or otherwise build an improved router from scratch. At the moment, the routing logic is about as basic as it could possibly be. There are many features that I want the router to have, including preventing route conflicts.

Are you interested in helping with this?

Hi Seth,
Sorry for taking this long to answer.
I'd love to help, however, lately I don't have a lot of free time. I'll take a look at call, maybe its an easy port :)

Just a minor update. I started writing my own router implementation from scratch - mostly as a learning exercise, but also so that pogo can use it if it turns out well or in case hapijs/call is difficult to port to Deno. I still think it would be good to use call, as that is a complex piece of code that is battle tested and it already has a lot of features that I probably won't be able to get around to in my own implementation anytime soon. Help on this would be much appreciated. But I should have a basic dynamic router in place within the next week or two.

I added an improved router in 9352e79 and b661df6, which brings support for:

  • Simple path parameters of the {userId} variety (required params)
  • Wildcard method handlers (method: '*' in route config)
  • server.inject() to make a request directly to the server without using the network (useful when writing tests)

There are still many improvements that should be made to the router. Among them, optional params and params that cover part of a segment or multiple segments are not yet supported. But it's a reasonable place to start and we can deal with the rest in separate issues. Let me know how it works for you!

I just published a new release with these changes, as well as other routing improvements and bugfixes.

https://github.com/sholladay/pogo/releases/tag/v0.2.0