I keep getting this error :
######################### ERROR STACKTRACE #########################
Expected end of input
Line: 0
Around: …11092×16 DataFrame Row…
But when I run the code (excluding the routes) in a separate terminal, it runs just fine, returning a DataFrame of securities symbols with some information about them.
What am I doing wrong? (Note that the api key published here is a publishable key that only has access to free data.)
using Genie, Genie.Renderer.Json, Genie.Requests
using HTTP, JSON
using DataFrames
route("/tickers", method = POST) do
message = jsonpayload()
# (:echo => (message["message"] * " ") ^ message["repeat"]) |> json
syms = HTTP.request("GET","https://acre.iex.cloud/v1/data/CORE/REF_DATA?token=pk_79891f5cbcce4099ae063588956f937a")
schema_req = HTTP.request("GET","https://acre.iex.cloud/v1/data/CORE/REF_DATA?schema=true&token=pk_79891f5cbcce4099ae063588956f937a")
sbs = syms.body |> String |> JSON.parse
smat = sbs .|> values .|> collect |> (x->reduce(hcat,x)) |> (x->permutedims(DataFrame(x,:auto)))
schema = schema_req.body |> String |> JSON.parse |> first |> keys |> collect
rename!(smat,Symbol.(schema))
end
route("/send") do
response = HTTP.request("POST", "http://localhost:8000/tickers", [("Content-Type", "application/json")], """{"exchanges":"XNYS", "type":"cs"}""")
response.body |> String |> JSON.parse
end
up(async = false)
Ultimately, I’d like the ‘/tickers’ route to be an API backend and the /send
route to exist in a desktop application (not necessarily as a webpage), so answers without relying heavily on formatting the /send
route are very welcome.
Thanks!
UPDATE:
I found out that changing the line
response.body |> String |> JSON.parse
to
response.body |> String |> Genie.Renderer.Json.json
gets rid of the error. I’m guessing it’s because Genie requires its own json
method to pass json objects, not JSON.parse
. (Also, I can’t just use ‘|> json
’ like in the Genie example, because the keyword json
is exported by two modules that I imported, so I have to specify that this is the Genie one.)
Now it looks like this, and I’d like to know of a way to receive a dataframe as a response and not this monstrosity. Any ideas?