Search code examples
rposthttr

Data from httr POST-request is long string instead of table


I'm receiving the data I'm requesting but don't understand how to sufficiently extract the data. Here is the POST request:

library(httr)
url <- "http://tools-cluster-interface.iedb.org/tools_api/mhci/"
body <- list(method="recommended", sequence_text="SLYNTVATLYCVHQRIDV", allele="HLA-A*01:01,HLA-A*02:01", length="8,9")
data <- httr::POST(url, body = body,encode = "form", verbose())

If I print the data with:

data

..it shows the request details followed by a nicely formatted table. However if I try to extract with:

httr::content(data, "text")

This returns a single string with all the values of the original table. The output looks delimited by "\" but I couldn't str_replace or tease it out properly.

I'm new to requests using R (and httr) and assume it's an option I'm missing with httr. Any advice?

API details here: http://tools.iedb.org/main/tools-api/


Solution

  • The best way to do this is to specify the MIME type:

    content(data, type = 'text/tab-separated-values')