ZnClient is your friend (it is a builder) :

ZnClient new
  url: 'http://some/thing';
  formAt: #foo put: #bar;
  formAt: 'baz' put: 'quux';
  post.

HTH,

Sven

PS: Check out the 'accessing request' protocol for more ways to construct your 
request. Also, the response is kept in the object: #post returns something 
called the contents, but you can add ; response or ; isSuccess at the end. 
Check out the class comment or unit tests.

On 02 Oct 2014, at 02:17, Benjamin Pollack <benja...@bitquabit.com> wrote:

> Hey all,
> 
> This is probably me missing something, but: for an upcoming
> presentation, I wanted to find the tersest way to demonstrate making an
> HTTP POST.  Something equivalent to Python's
> 
>    requests.post('http://some/thing', data={'foo': 'bar', 'baz':
>    'quux'})
> 
> The closest I could come up with for Pharo was
> 
>    ZnEasy post: 'http://some/thing' data:
>    (ZnApplicationFormUrlEncodedEntity withAll: {
>        'foo' -> 'bar'.
>        'baz' -> 'quux'.
>    } asDictionary)
> 
> I just wanted to verify that is, in fact, the shortest way to do this. 
> I feel as if I'm almost certainly missing a utility method around the
> ZnApplicationFormUrlEncodedEntity bit, and, especially for demos,
> terseness matters.  (It's obviously trivial to write a utility method if
> this *is* the shortest way to do this, but then people in the audience
> won't be able to execute the resulting code snippet without the utility
> method.)
> 
> Thanks,
> 
> --Benjamin
> 


Reply via email to