[Seaside] Rest and POST method

Norbert Hartl norbert at hartl.name
Wed Apr 6 16:11:34 UTC 2011

Am 06.04.2011 um 14:53 schrieb Olivier Auverlot:

> To infinite... and beyond !
I hope this wasn't a complaint :) I really like your using of rawBody. For just sending XML it is a good idea. Most of the time I use multipart messages an there rawBody doesn't help. In absence of multipart/related handling I just define the part "root" as the default one that carries the XML and the other parts are referenced from there

If you like to try Magritte-XML you can take a short cut. Define

Object subclass: #User
	instanceVariableNames: 'fullName emailAddress password'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Imagined-Model'

getter/setter for the instance variables

User class>descriptionContainer
	^ super descriptionContainer 
		xmlElementName: 'user';

User class>>descriptionFullName
	^ MAStringDescription new
		accessor: #fullName;
		priority: 100;
		label: 'full name';

User class>>descriptionEmailAddress
	^ MAStringDescription new
		accessor: #emailAddress;
		priority: 110;
		label: 'email address';
		xmlAttributeName: 'email';

User class>>descriptionPassword
	^ MAStringDescription new
		accessor: #password;
		priority: 120;
		label: 'password';


If you do 

| user |
user := COUser new
   fullName: 'John Doe';
   emailAddress: 'john at doe.com';
   password: 'fobar'.

User description toXml: user 

you should get

'<user email="john at doe.com" fullName="John Doe"/>'

If you have only one description and you need easy printing than adding the following methods to your model objects might be feasible.

	^ String streamContents: [:stream|
		self printXMLOn: stream  ]  

User>>printXMLOn: aStream
	aStream nextPutAll: (self description toXml: self)

Hope it helps,


> Le 06/04/11 14:38, Philippe Marschall a écrit :
>> 2011/4/6 Olivier Auverlot<olivier.auverlot at gmail.com>:
>>> I have modified the code with the following modifications :
>>> HttpRequest>>#rawPostFields
>>>    ^self propertyAt: #rawPostFields ifAbsentPut: [
>>>        (self isPostRequest) ifTrue: [
>>>            stream next: self contentLength
>>>        ] ifFalse: [
>>>            ''
>>>        ].
>>>    ]
>>> Now, it seems ok. I can send GET or POST requests and send XML data. For
>>> read this data, I use the rawBody propertie.
>>> For example:
>>> postXML
>>> <POST>
>>> <Consumes: 'text/xml'>
>>> <Path: '/postxml'>
>>>    Transcript show: self requestContext request rawBody.
>>> Now, I must find a cool tool for parsing XML...
>> Magritte-XML ;-)
>> Cheers
>> Philippe
>> _______________________________________________
>> seaside mailing list
>> seaside at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

More information about the seaside mailing list