SWI-Prolog / packages-http

The SWI-Prolog HTTP server and client libraries
23 stars 23 forks source link

http_post with json-data #118

Closed ruediarnold closed 5 years ago

ruediarnold commented 5 years ago

I don't know whether this is a bug or a feature...

When I use http_post with json-data, I have to wrap the json-data two times with the json-marker-predicate 'json'. Working example:

?- http_post('https://postman-echo.com/post/', json(json([test=aha])), Response, []).

When don't double-wrap the json, it won't work:

?- http_post('https://postman-echo.com/post/', json([test=aha]), Response, []). ERROR: Type error: ``json_term' expected, found ``test=aha' (a compound) ...

Now my question: bug or feature?

If it's a bug, could it be fixed? Or am I doing this completely wrong?

If it's a feature, could it be documented e.g. in http://www.swi-prolog.org/pldoc/doc_for?object=http_post/4 and/or in http://www.swi-prolog.org/pldoc/man?section=json - Or is it already documented and I just didn't find it?

Thank you very much!

Cheers, Ruedi

JanWielemaker commented 5 years ago

bug or feature

Feature. The first tells the API we have a json object, the term happens to be json also, but could be json([a,b,c]) or json(_{x:1,y:2})