ZnClient: how to emulate a curl command

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ZnClient: how to emulate a curl command

Offray Vladimir Luna Cárdenas-2
Hi,

I'm prototyping some integration between Fossil and Pharo for the
creation of dynamic distributed web sites [1]. Now I would like to send
some messages to store serialized STON domain objects as Fossil wiki
pages. The command that makes this, using curl, is:

curl -H "Content-Type: application/json" -d '{"authToken": "mytoken",
"payload": {"name": "foo", "content": "bar"}}'
http://localhost:8081/json/wiki/create

and I thought that a similar command would be the one at [2], but there
is something about ZnEntity that I'm not understanding.

How can I replicate the curl command using ZnClient?

[1] http://smalltalkhub.com/#!/~Offray/Brea
[2] http://ws.stfx.eu/D61ZOA1LEQNG

Thanks,

Offray



Reply | Threaded
Open this post in threaded view
|

Re: ZnClient: how to emulate a curl command

Sven Van Caekenberghe-2
Hi Offray,

> On 7 Jun 2017, at 17:21, Offray Vladimir Luna Cárdenas <[hidden email]> wrote:
>
> Hi,
>
> I'm prototyping some integration between Fossil and Pharo for the
> creation of dynamic distributed web sites [1]. Now I would like to send
> some messages to store serialized STON domain objects as Fossil wiki
> pages. The command that makes this, using curl, is:
>
> curl -H "Content-Type: application/json" -d '{"authToken": "mytoken",
> "payload": {"name": "foo", "content": "bar"}}'
> http://localhost:8081/json/wiki/create
>
> and I thought that a similar command would be the one at [2], but there
> is something about ZnEntity that I'm not understanding.
>
> How can I replicate the curl command using ZnClient?
>
> [1] http://smalltalkhub.com/#!/~Offray/Brea
> [2] http://ws.stfx.eu/D61ZOA1LEQNG
>
> Thanks,
>
> Offray

That [2] looks about right to me. Though the URL is strange (the json part). What do you get as response ? Maybe the authentication just fails. Or you made some other mistake ?

I would personally never write JSON manually, but like this:

STONJSON toString: { #authToken->'foo'. #payLoad->({ #name->'test'. #content->'something' } asDictionary) } asDictionary.

Or this:

(NeoJSONObject new authToken: 'foo'; payLoad: (NeoJSONObject new name: 'test'; content: 'something')) asString.

Different styles/frameworks, same result.

Sven


Reply | Threaded
Open this post in threaded view
|

Re: ZnClient: how to emulate a curl command

Offray Vladimir Luna Cárdenas-2
Hi Sven,

I was making a silly mistake in the server URL. I just forgot the extra
"/" after servers port number, so it was "8081/json" instead of
"8081json". I imagine that maybe is a test for validating properly form
urls, but also I will have a more trained eye for such errors next time.
Now is working properly. The code at [1], shows the fix and includes the
ZnEasy convenience.

[1] http://ws.stfx.eu/PLUA8QCSI4X0

Cheers,

Offray


On 07/06/17 12:20, Sven Van Caekenberghe wrote:

> Hi Offray,
>
>> On 7 Jun 2017, at 17:21, Offray Vladimir Luna Cárdenas <[hidden email]> wrote:
>>
>> Hi,
>>
>> I'm prototyping some integration between Fossil and Pharo for the
>> creation of dynamic distributed web sites [1]. Now I would like to send
>> some messages to store serialized STON domain objects as Fossil wiki
>> pages. The command that makes this, using curl, is:
>>
>> curl -H "Content-Type: application/json" -d '{"authToken": "mytoken",
>> "payload": {"name": "foo", "content": "bar"}}'
>> http://localhost:8081/json/wiki/create
>>
>> and I thought that a similar command would be the one at [2], but there
>> is something about ZnEntity that I'm not understanding.
>>
>> How can I replicate the curl command using ZnClient?
>>
>> [1] http://smalltalkhub.com/#!/~Offray/Brea
>> [2] http://ws.stfx.eu/D61ZOA1LEQNG
>>
>> Thanks,
>>
>> Offray
> That [2] looks about right to me. Though the URL is strange (the json part). What do you get as response ? Maybe the authentication just fails. Or you made some other mistake ?
>
> I would personally never write JSON manually, but like this:
>
> STONJSON toString: { #authToken->'foo'. #payLoad->({ #name->'test'. #content->'something' } asDictionary) } asDictionary.
>
> Or this:
>
> (NeoJSONObject new authToken: 'foo'; payLoad: (NeoJSONObject new name: 'test'; content: 'something')) asString.
>
> Different styles/frameworks, same result.
>
> Sven
>
>
>