adding routes/endpoints dynamically

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

adding routes/endpoints dynamically

johannes
Hi,

I want to be able to add handlers (routes) dynamically/at runtime.

any pointers?
tia
Jpn
Reply | Threaded
Open this post in threaded view
|

Re: adding routes/endpoints dynamically

Luke Daley
Administrator
Context#insert() is what you need.

I can give you more help if you provide more information.
Reply | Threaded
Open this post in threaded view
|

Re: adding routes/endpoints dynamically

johannes
how much info do you want!

I am using ratpack to mock our spring apps rendering and data. I don't want to go into detail, but the result I am looking for is
1) be able to scan a folder, pickup each file (recursively) and create a route for it (so I can accomplish something like an http rewrite rule) for development mode (uncompiled js files - google closure user)

2) (this one is out of scope of the original question) dependent on a groovy script binding, be able to serve data in synchronous mode from a static file, or using some groovy magic implement a mini reverse proxy to talk to our dev and integration servers.

this is all done so our ux devs don't have to start up our project, hazelcast cluster, all the rabbit queues bla bla
Reply | Threaded
Open this post in threaded view
|

Re: adding routes/endpoints dynamically

Luke Daley
Administrator
1) be able to scan a folder, pickup each file (recursively) and create a route for it (so I can accomplish something like an http rewrite rule) for development mode (uncompiled js files - google closure user)
If you want to create handlers dynamically, you can do any logic you want in the handlers {} blockā€¦

<code>
ratpack {
  handlers {
    for (thing in things) {
      get(thing.path) {
        response.send thing.value
      }
    }
  }
}
</code>

It's unlikely Ratpack will get in your way here. The handler structure is very flexible.

2) (this one is out of scope of the original question) dependent on a groovy script binding, be able to serve data in synchronous mode from a static file, or using some groovy magic implement a mini reverse proxy to talk to our dev and integration servers.
I don't quite understand what you mean here.