[Pharo-users] Using ZnClient>>#contentWriter

Esteban Maringolo emaringolo at gmail.com
Thu Feb 21 17:36:23 EST 2019

Hi all,

I'm doing this and it works
ZnClient new
  method: #PUT;
  url: '';
  contents:  (NeoJSONWriter toString: { 'foo' -> 'baz'} asDictionary);
  contentType: ZnMimeType applicationJson;

But if try to use a contentWriter it fails because it can't determine
the contentType of the entity.

ZnClient new
  method: #PUT;
  url: '';
  "contentType: ZnMimeType applicationJson;"
  contentWriter: [ :entity | NeoJSONWriter toString: entity ];
  contents:  { 'foo' -> 'baz'} asDictionary;

If I uncomment the "contentType:" message send it complains about
setting the content type before setting the entity, which makes sense
but baffles me.

My Idea is to directly pass the object as contents, and let the
content writer deal with how it's going to be serialized on the
request (a JSON string, for the most part).

Although the first expression works, I know it can be done better, but
I can't manage to get it working :)


ps: I also wonder by there aren't #bePut, #bePost, #beDelete, etc.
convenience methods instead of passing the HTTP method as a symbol :)

Esteban A. Maringolo

More information about the Pharo-users mailing list