Client side upload of a JSON file, string or URL with BDS data, checks the data,
stores its contents as a tibble with a person attribute on host,
and returns an object of class httr::response()
that contains the results of the request.
Arguments
- txt
Data set. Could be a URL, local file, JSON string or JSON object.
- host
String with the host. The default is
"http://localhost"
.- format
String. JSON data schema version number. There are currently three schemas supported:
"1.0"
,"1.1"
and"2.0"
. Formats"1.0"
and"1.1"
are included for backward compatibility only. Useformat = "2.0"
for new applications.- schema
A file name (optionally including the path) with the JSON validation schema. The
schema
argument overridesformat
. The function extracts the version number for the basename, and overwrites theformat
argument by version number.- verbose
Logical. Print diagnostic information of POST request to console.
Value
An object of class httr::response()
Details
JSON format: See https://stefvanbuuren.name/jamesdocs/getting-data-into-james.html for the specification of the JSON format.
User agent: The function upload_txt()
searches for an object called ua
on the search
list. The ua
object is an optional user agent, a request that identifies
yourself to the API. For example, run
httr::user_agent("https://github.com/myaccount")
(with
myaccount
replaced by your github user name) before
calling upload_txt()
. See
https://httr.r-lib.org/articles/api-packages.html for details. Setting
the user agent is not required.
Append "/json"
to path
and set query = "auto_unbox=TRUE&force=TRUE"
to obtain a partial JSON representation of the S4 class individual
. At present, it is not
possible to rebuild the S4 class individual
from its JSON representation because
the S4 class depends on environments, and these are not converted to JSON.
Warning: The S4 class
individual
is an internal format that is in development. It is likely to
change, so don't build applications based on this data structure. If you need
components from the internal structure (e.g. Z-scores, brokenstick estimates) it
is better to develop a dedicated API for obtaining these.
Examples
if (FALSE) {
library(httr)
host <- "http://localhost"
url <- paste(host, "ocpu/library/jamesdemodata",
"extdata/bds_v2.0/smocc/Laura_S.json", sep = "/")
fn <- system.file("extdata", "bds_v2.0", "smocc", "Laura_S.json",
package = "jamesdemodata", mustWork = TRUE)
js1 <- readLines(url)
js2 <- jsonlite::toJSON(jsonlite::fromJSON(url), auto_unbox = TRUE)
# upload JSON file
r1 <- upload_txt(fn, host)
identical(status_code(r1), 201L)
# upload JSON string
r2a <- upload_txt(js1, host)
identical(status_code(r2a), 201L)
r2b <- upload_txt(js2, host)
identical(status_code(r2b), 201L)
# upload JSON from external URL.
r3 <- upload_txt(url, host, format = "1.0")
identical(status_code(r3), 201L)
# browseURL(file.path(get_url(r3), "print"))
# browseURL(file.path(get_url(r3), "json"))
}