[Seaside] Seaside and REST

John Thornborrow john at pinesoft.co.uk
Thu May 3 08:38:08 UTC 2007

Lukas Renggli wrote:
>> 2) a subclass of WARenderLoopMain implementing #start: and possibly
>> #createRoot.
>> (here is some pseudo code for this subclass but I'll send you a
>> working example if you want)
>> start: aRequest
>>         | path decision |
>>         path := aRequest url findTokens: $/.
>>         decision := path interrogateMe.
>>         state := InitialState newBasedOn: decision.
>>         super start: aRequest
>> createRoot
>>         | root |
>>         root := super createRoot.
>>         root initialiseWithState: state.
>>         ^ root
> Overriding WAComponent>>#initialRequest: can sometimes avoid the extra
> subclass of WARenderLoopMain. Moreover the code is the closer to the
> counterpart #updateRoot:
> Cheers,
> Lukas
Just to add to Lukas' message above:

I have found over riding #initialRequest: on my root object to be the
easiest method of implementation.
I have a whitelist of keywords to use, then serve the content according
to that via my registry object.
Something like (paraphrased and simplified..)

initialRequest: aRequest
    | url tokens components |
    components _ Dictionary new at: 'main' put: SomeComponentClass;
yourself. "more components added as needed"
    url _ aRequest copyFrom: ('/seaside/applicationname/' size) to: 
(aRequest url size).
    (url size > 1)
        ifTrue: [
            tokens _ url findTokens: '/'.
            self registry at: 'content' put: (components at: (tokens at:
1) ifAbsent: [DefaultComponentClass]) new]
        ifFalse: [self registry at: 'content' put: DefaultComponentClass

and in part of my root objects #renderContentOn: method..

renderContentOn: html
    html render: (self registry at: 'content')

In reality I have a fairly complex object structure of defining dynamic
"routes" which follows the practice of Apache's ReWrite module and
principles. (complex, but easy to use of course!)



Pinesoft Computers are registered in England, Registered number: 2914825. Registered office: 266-268 High Street, Waltham Cross, Herts, EN8 7EA

This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com

More information about the Seaside mailing list