1

Apologies upfront. This is a complete newbie question about concepts that I'm not at all familiar with. I'm also new to R!

I'm trying to access some data via a web API.

I was expecting the response to my Get to contain some simple structured data (a csv file) that I could read into a data frame in R for manipulation.

However, I'm informed that the response of the endpoint that I'm hitting is a "zip-stream".

What the heck is a "zip-stream" and how can I manipulate it in R to get the data that I need into a data frame?

  • If they mean the content is gzipped/deflated then httpr should take care of it for you, have you tried making a request as normal? If you open the URL in a browser and look at the networking debug tab you can look at the response headers which will should describe the content type. – Alex K. Jun 20 '19 at 16:00
  • Thanks. I made a request (actually a POST not a GET as I said originally). I get a response back and the content type is raw. – jabbathewatts Jun 20 '19 at 16:10
  • Isn't a zip-stream a way to access zip files without writing it on the disk? – Gainz Jun 20 '19 at 16:11
  • You should provide a link to the reference that defines the endpoint or provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so that I might better be able to tell what they mean from context or testing. As far as I know the term "zip-stream" doesn't have a clear, unambiguous meaning. – MrFlick Jun 20 '19 at 16:15

1 Answers1

0

It sounds as though the response from the API is the contents of a zip file.

Rather than trying to read the stream you can write to a file by adding a write_disk to the httr request to capture e.g. POST(url, ....,write_disk("filename.zip")

You can then use unzip(filename) to open up the zip and extract the files.

The API documentation should explain the format of the files and help you choose how to best to load the resulting file and process them.

Does this help?

There maybe some other ideas worth trying here: Download File in R with POST while sending data

Jamie
  • 38
  • 1
  • 5