Parameterised paths for Altitude?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Parameterised paths for Altitude?

Frank Shearar-3
Hi Colin,

I'm playing around with Altitude, making something that can reflect on
an image. So for instance I have in my main ALApplication subclass

        #(hash value) do: [:sym |
                locator
                        at: ALPath root / 'senders-of' / sym asString
                        put: (SendersOf reflecting: sym) asResource]

but I'd really rather have something like this Sinatra snippet:

        get '/senders-of/:name' { |n|
                # Get the senders of :name
        }

I can't find any Locators like that, so perhaps it's not something
you've needed?

frank

Reply | Threaded
Open this post in threaded view
|

Re: Parameterised paths for Altitude?

Colin Putney-3
On Fri, Jul 27, 2012 at 1:56 PM, Frank Shearar <[hidden email]> wrote:

> Hi Colin,
>
> I'm playing around with Altitude, making something that can reflect on
> an image. So for instance I have in my main ALApplication subclass
>
>         #(hash value) do: [:sym |
>                 locator
>                         at: ALPath root / 'senders-of' / sym asString
>                         put: (SendersOf reflecting: sym) asResource]
>
> but I'd really rather have something like this Sinatra snippet:
>
>         get '/senders-of/:name' { |n|
>                 # Get the senders of :name
>         }
>
> I can't find any Locators like that, so perhaps it's not something
> you've needed?

I have done something a bit like that, but it was specific to my
application, so I didn't include it in the framework. Basically,
there's two ways to approach it. One is to make everything automatic,
which is really simple, but produces ugly (but RESTful) URLs. For
that, you just have to do something like this:

ReflectionApplication>>initializeLocator
    locator
        at: ALPath root
        put: (EnvironmentEndpoint reflecting: Smalltalk globals)

Then EnvironmentEndpoint would create links to other endpoints
reflecting various bits of the system, the locator would auto-generate
urls, and off you'd go.

If you want to generate pretty urls, you'd need to write a custom
Locator. This is a bit messy at the moment. I'd like to have Locator
use a the Strategy pattern to delegate construction and interpretation
of paths to another object, but that'll require a bit of refactoring.
In the meantime, a custom locator that implements #pathForResource:
and #resourceForPath: should give you what you need.

Note that in general, you don't want to do a lot in
#initializeLocator. That's meant to handle the root path, plus any
static urls you need for things like Javascript or CSS. For the core
functionality of the application, the locator its self should provide
your routing.

Colin