For sending a vector of values, say an array list_a = c(1,2,3)
FastAPI will accept a URL of the form:
https://wherever.com/endpoint?list_a=1&list_a=2&list_a=3
However using library httr's query parameter to the GET function, you have to pass a list of key/value pairs. This means you can't have the same field twice because R will not accept a list with duplicate keys obviously.
So how do I do this? I could build the URL myself, but the problem with that is some of my parameters have double quotes ("
) in them which don't seem to be parsed properly if I put them directly into the url. The query
parameter does seem to handle these properly however.
Is there any way to get the query
parameter of httr's GET
to create multiple identical field names?
Alternatively how do I encode a pre-created URL that has double quotes in it like the one below so that it does not cause FastAPI to give at HTTP error?
"query/Crude/?actual_table_name=live.crude&report_id=xxxxxxx&fields=IMO&where={\"Barrels\":{\"gt\":1},\"conjunction\":\"\"}&where={\"Load Date\":{\"gt\":\"'2000-01-01'\"},\"conjunction\":\"\"}&offset=1e+05&limit=10000"
I think it would be easiest to build the query string yourself, then you could use URLencode
on the result:
url <- "query/Crude/?actual_table_name=live.crude&report_id=xxxxxxx&fields=IMO&where={\"Barrels\":{\"gt\":1},\"conjunction\":\"\"}&where={\"Load Date\":{\"gt\":\"'2000-01-01'\"},\"conjunction\":\"\"}&offset=1e+05&limit=10000"
URLencode(url)
#> [1] "query/Crude/?actual_table_name=live.crude&report_id=xxxxxxx&fields=IMO&where=%7B%22Barrels%22:%7B%22gt%22:1%7D,%22conjunction%22:%22%22%7D&where=%7B%22Load%20Date%22:%7B%22gt%22:%22'2000-01-01'%22%7D,%22conjunction%22:%22%22%7D&offset=1e+05&limit=10000"