15/08/2008

Setting a static URL for an application

I want to provide an api for some of my future apps. That means that I need to be able to define static urls and handle requests to them.

To do this, you have to override Class>>initialRequest. Something like this:

initialRequest: aRequest

super initialRequest: aRequest.
aRequest fields at: 'action' ifPresent:
[:action | 'put'=action ifTrue:[self confirm: 'you want to put']. 'get'=action ifTrue:[self confirm: 'you want to get?']].


I have a little way to go on this, because at the moment it is only processing the url argument, whereas I want to get to the contents of a 'posted' document. However, I am sure that will just be an object message away ;-)

2 comments:

Ramon Leon said...

Why would you want to be parsing the request to get anything? The whole point of Seaside is that you don't have to do this stuff anymore, you bind your form directly to your model and Seaside does all that for you and updates your model directly.

initialize
model := SomeObject new.

save
model inspect.

renderContentOn: html
html form: [
html textInput on: #name of: model.
html submitButton on: #save of: self]

The button is bound to the controller action #save and the input is databound directly to the model, you don't have to do anything.

BTW, you don't need to look in the initalRequest: to get posted params either, from anywhere in your component you can just say

self fieldAt: #someParam

And you got it, directly going to the raw request is rarely necessary.

Andy Burnett said...

I love the internet, even my idly musings help me learn things from other people :-)

In answer to Ramon's question about "why would I want to be parsing...", it may well be that I don't want to! My thought was that for another application e.g. Excel to be able to read or write data to my Seaside app, it would need to have a static URL to call, and possibly pass in arguments. If that is the case, then somehow I need to be able to process them.

However, Ramon's comment suggest that I am still not thinking about this the right way at all - on we go :-)