Read .csv with Javascript fetch

Photo by Mika Baumeister on Unsplash

Commonly, we use fetch() with method get to read JSON from a server. But sometimes we may need to read .csv file, or retrieve csv-structure-data.
Well, it’s surprisingly easy. Just edit the header to text/csv, and use res.text() instead of res.json()

In case you want the server to response in .csv. Just use json2csv to parse the data.

--

--