I have curl post to implement in pharo, but it seems like there is not much in term of explanation on how to do that. I saw few example but they ARE way simpler than what I need to. I would you do that inn pharos?
$ curl 'https://url_server' \
-X POST \
-H 'key: MY PASSWORD' \
-H 'Content-Type: application/json' \
-d \
'{
"HEADER": "FOO",
"DESK": "POO",
"FORWARDTO": "another_url"
}'
I know that this is similar to post using Znclient like so:
ZnClient new
url: 'url_server';
entity: (ZnEntity
with:'{"HEADER": "FOO",
"DESK": "POO",
"FORWARDTO": "another_url"}'
type: ZnMimeType applicationJson
);
post.
However where does the key goes to using this syntax?
Seems like you are looking for the way to set a HTTP header field for your request in Zinc?
Try ZnClient
:
headerAt: key put: value
"Set key equals value in the HTTP header of the current request"
Your code then could look like:
ZnClient new
url: 'yourURL';
headerAt: 'headerKey' put: 'headerValue';
entity: (ZnEntity
with:'{"yourJSON": "Content"}'
type: ZnMimeType applicationJson);
post.
Zinc also has a nice feature, that shows you a curl command line invocation equivalent to the current request. So you can compare to the curl line you had in mind. Just print:
ZnClient new
url: 'yourURL';
headerAt: 'headerKey' put: 'headerValue';
entity: (ZnEntity
with:'{"yourJSON": "Content"}'
type: ZnMimeType applicationJson);
method: #POST;
curl.
You'll find a good documentation for using Zinc HTTP as client in the Enterprise Pharo book.