residuum / PuRestJson

PuREST JSON is a library for connecting Puredata (Pd) to HTTP services and encoding and decoding JSON data.
ix.residuum.org/pd/purest_json.html
Other
74 stars 9 forks source link

rest object blocks #36

Closed hkopp closed 9 years ago

hkopp commented 9 years ago

The object "rest" does not support streaming IO. It does not send output when the server does not close the connection.

For example GET requests on http://stream-sandbox.oanda.com/v1/prices?instruments=EUR_USD do not work. Unfortunately I cannot attach a pd-file. If you have any problems reproducing the behaviour, I can attach a jpg.

residuum commented 9 years ago

This is by design. In Pd, you will need some kind of a message to output from the object.

What is your desired result of the request? Should it output everything that it got on every cycle? Should it collect some arbitrary length of data and then output it? Should it use linebreaks as separators (as in your example)?

It would need a need a new message, [mode(, with at least two possible values [mode line( and [mode blocking(, the latter being the default, just to stay compatible.

hkopp commented 9 years ago

Thinking about it, you are right. The mode-message would be the cleanest solution. But then I get problems later, since the json-decode object should also be handle to able streams as input and output an object every time, the input is fully parsed.

residuum commented 9 years ago

If [rest] outputs the content line by line, then in your example, [json-decode] can decode the values. But it would definitely require a different mode.

I will have a look at libcurl and how to output the stream line by line.

residuum commented 9 years ago

I have just created a branch for that and at least implemented the [mode( message.

This will need some rework of the output / memory callback implementations, I will look into it.

hkopp commented 9 years ago

Thanks

residuum commented 9 years ago

What is still missing, is writing to file in streaming mode.

The help patch currently generates a segfault, i will look into that later.

After that, I will update the help patches, and then will merge the branch to master.