On 04/02/2016 05:00 AM, r-help-requ...@r-project.org wrote:
Hello,
I'm looking for a way in which R can make my live easier.
Currently i'm using R convert data from a dataframe to json's and then sending
these json's to a rest api using a curl command in the terminal (i'm on a mac).
I've been looking for a way to use R for sending data from R to the rest api.
My primairy focus was on using R for executing the curl command, however, I'm
open to other approaches. The method I've been using so far:
-----------------
These are lines snipped from a working application. I make use of the httr package. The
parameters of the call are assembled as a nested list "xlist" prior to this section. The
set of errors I check for is unique to the API I'm talking to, an internal one that's a
bit odd in its return codes, but still it gives you the idea.
auth <- authenticate(id$lanid, id$password, type="basic")
query <- POST(url=control$posturl, body= xlist, auth, encode="json")
if (status_code(query) >= 300) handle_reset(control$posturl)
if (status_code(query) == 401)
stop("invalid lanid/password for this application")
else if (status_code(query) == 400)
stop("internal error from dart package: 'syntax of request'")
else stop_for_status(query) #other query errors, e.g. server down
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.