Can http_persist_get return a string instead of writing to a file

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
rwillis2916
Posts: 7
Joined: Thu Jul 10, 2025 6:12 pm

Can http_persist_get return a string instead of writing to a file

Post by rwillis2916 »

On the http_persist_get procedure, instead of calling a file writer in the 3rd parm, can I override it to another procedure? I don't really need the data written to a file. I would just like to have the json returned in a string. If possible, please point me to a working example.
Scott Klement
Site Admin
Posts: 896
Joined: Sun Jul 04, 2021 5:12 am

Re: Can http_persist_get return a string instead of writing to a file

Post by Scott Klement »

http_persist_get() cannot write to a file. It can only return the results via a callback procedure. You can write that procedure to do anything you want.

Can you explain why you want to use http_persist_get? I don't recommend it. Use http_req() instead.
rwillis2916
Posts: 7
Joined: Thu Jul 10, 2025 6:12 pm

Re: Can http_persist_get return a string instead of writing to a file

Post by rwillis2916 »

I'm calling an API that returns a large amount of data in total. But in small chunks. So I'm using http_persist_open, then http_persist_get to pull in the first chunk of data. If there's more data to receive, I do a loop and continue to call http_persist_get until al data has been received. With this form, writing to a file and reading the JSON data back in each time is really slow. I can test to see if using HTTP_req multiple times would be faster. Thanks.

Question, is there a way to mark a post on here as closed? Or Resolved?
Scott Klement
Site Admin
Posts: 896
Joined: Sun Jul 04, 2021 5:12 am

Re: Can http_persist_get return a string instead of writing to a file

Post by Scott Klement »

rwillis2916 wrote: Wed Jul 30, 2025 4:56 pm I'm calling an API that returns a large amount of data in total. But in small chunks. So I'm using http_persist_open, then http_persist_get to pull in the first chunk of data. If there's more data to receive, I do a loop and continue to call http_persist_get until al data has been received.
That will work, but if there's a network error or deliberate disconnection you will have to handle it in your code. Why not request all of the data in one call? That would greatly simplify things rather than receiving it in pieces. The purpose behind the callback routine (as well as the one in http_url_get) is to obviate the need for a separate connection to get each chunk of data.
rwillis2916 wrote: Wed Jul 30, 2025 4:56 pm With this form, writing to a file and reading the JSON data back in each time is really slow. I can test to see if using HTTP_req multiple times would be faster. Thanks.
Your initial question asked about receiving it to a string (that's what http_req will do, but it's possible to do the same with http_persist_req, http_persist_get, or http_get_raw). But you also say the data is very large, and in RPG strings are limited to 16 mb. A file will allow up to 2 TB.

Then you say files are slow... I'm very skeptical of this. True they aren't as fast as strings (of course) but with processing data that large, the disk access time is tiny by comparison to everything else going on.
rwillis2916 wrote: Wed Jul 30, 2025 4:56 pm Question, is there a way to mark a post on here as closed? Or Resolved?
This is a discussion forum, not a list of tasks or bugs. So "resolved" really doesn't make sense in this context. But it can be closed preventing further discussion.
Post Reply