How do I return a CSV response? I want the user to be able to curl and endpoint and they should up with a csv file.
create an io/writer, write into that, then feed it into the http://ring.util.io like this:
(-> (your-writer-function)
(rio/piped-input-stream)
(response/response)
(response/content-type "text/csv; charset=UTF-8")
(response/header "Content-Disposition" "attachment; filename=foobar.csv"))))Thank you!
I'm testing this out. How do I create the io/writer?
I have this now:
(defn write-csv
"Takes a file (path, name and extension) and
csv-data (vector of vectors with all values) and
writes csv file."
[file csv-data]
(with-open [writer (io/writer file)]
(csv/write-csv writer csv-data)))
So I have tho io/writer, but it's writing to a file. And it's being written to by csv/write-csv. I'm uncertain about what goes where.