Hi Asbath,
From what I can see in the code included in the email, you wrote a POST handler that expects/accepts JSON, while the client call sends a application/x-www-form-urlencoded payload.
You need to send JSON data. The following creates a client that sends and expects JSON. ZnClient new url: 'http://localhost:8888/test'l; accept: ZnMimeType applicationJson; contentReader: [ :entity | entity ifNotNil: [ NeoJSONReader fromString: entity contents ] ]; contentWriter: [ :object | ZnEntity with: (NeoJSONWriter toString: object) type: ZnMimeType applicationJson ]. To send data along, you can just pass it using #contents: client contents: { #username->'john'. #password->'secret } asDictionary. The #contentWriter will do the conversion. Finally, you execute using #get, #put, #post or #delete. You could also use any object that has a #neoJsonMapping. Have a look at section 11.3 in https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBook/lastSuccessfu... as well as the whole chapter. HTH, Sven
On 2 Jan 2017, at 18:41, Asbath Sama biyalou via Pharo-users <pharo-users@lists.pharo.org> wrote:
From: Asbath Sama biyalou <asamabiyalou@yahoo.com> Subject: Rest post methods Date: 2 January 2017 at 18:41:30 GMT+1 To: Pharo users users <pharo-users@lists.pharo.org>
Hello Everybody. I am implementing an architecture of rest services like in TinyBlog tutorial. Now I want to implement post methods. But it doesn't work. My execute function execute | user u |
[ user := NeoJSONReader fromString: self context request rawBody. u := User new pseudo: (user at: #pseudo); numero_telephone: (user at: #numero_telephone). user save. ] on: Error do: [ self context request badRequest ]. self dataType: WAMimeType textPlain with: ''
neojsonmapping on class User
neoJsonMapping: mapper mapper for: self do: [ :mapping | mapping mapAllInstVars ]
The restfilter consumes */json.
I test it with ZnClient but that is not working. ZnClient new url: 'http://localhost:8080/Application/users/add'; formAt: 'pseudo' put: 'Big man'; formAt: 'numero_telephone' put: '99546321'; post.
I don't know what is the matter.
Thanks.
Asbath