$result = $client->post('http://localhost:12345/myRscript', ['parameter', 'some value'])
and get back a (JSON or HTML) string as a result
There is an example on the very first paragraph of the readme.
library(RestRserve)
app = Application$new()
app$add_get(
path = "/health",
FUN = function(.req, .res) {
.res$set_body("OK")
})
app$add_post(
path = "/addone",
FUN = function(.req, .res) {
result = list(x = .req$body$x + 1L)
.res$set_content_type("application/json")
.res$set_body(result)
})
backend = BackendRserve$new()
backend$start(app, http_port = 8080)
Why it doesn't work for you?
which host/ip the server binds to?See very first example in the readme:
backend$start(app, http_port = 8080)
toJSON
you set dataframe = 'columns'
. We had to specify our own encoder because the client didn't want boxed values -- and your default produces different output from plumber when the latter has the unboxedJSON
decorator set.
: by default in wrapping toJSON you set dataframe = 'columns'. We had to specify our own encoder because the client didn't want boxed
That's up to end user, you can always amend encoders and change middleware completely. As for default - I still believe that encode my columns is right choice. Essentially dataframes are column-oriented data structures, encoding them by column is most effective. And what is more important - most of the http clents will expect them as column encided
I still believe that encode my columns is right choice. Essentially dataframes are column-oriented data structures, encoding them by column is most effective.
I'm neither agreeing nor disagreeing with your choice, though I'm unsure if it's true clients would expect boxed values. I'm merely pointing out that RestRserve isn't quite a drop-in replacement for plumber because of this. Yet I do expect there's a use case there -- people work with plumber because it's so simple, then find they need something like RestRserve when moving to production.
Right, so the question is, can one bind to a specific address, e.g. the loopback? If not, are you open to a PR that does so?
So far this is controlled by Rserve. Here is reference for all the options - https://github.com/s-u/Rserve/wiki/rserve.conf. According to that you can specify backend$start(app, http_port = 8080, remote='false')
to allow only loopback connections.
Hi all,
Is there an option to have both cors and auth middlewares?
Also, since I am not very good at API's, I implemented the following structure with CORS:
1 - User sends a post with username+password
2 - API creates a token (random chars), saves a copy using sodium in the DB
3 - all new requests are now using the token as param in the POST
4 - when logout, token is deleted
Is this secure enough? Thank a lot for the help
request$get_file("csv")
returns NULL> request$body %>% rawToChar()
[1] "------WebKitFormBoundaryd7uvIHAPkNBzB7XG\r\nContent-Disposition: form-data; name=\"file\"; filename=\"cantons_4.csv\"\r\nContent-Type: application/vnd.ms-excel\r\n\r\n\"x\"\r\n\"AG\"\r\n\"AI\"\r\n\"AR\"\r\n\"BE\"\r\n\"BL\"\r\n\"BS\"\r\n\"FR\"\r\n\"GE\"\r\n\"GL\"\r\n\"GR\"\r\n\"JU\"\r\n\"LU\"\r\n\"NE\"\r\n\"NW\"\r\n\"OW\"\r\n\"SG\"\r\n\"SH\"\r\n\"SO\"\r\n\"SZ\"\r\n\"TG\"\r\n\"TI\"\r\n\"UR\"\r\n\"VD\"\r\n\"VS\"\r\n\"ZG\"\r\n\"ZH\"\r\n\r\n------WebKitFormBoundaryd7uvIHAPkNBzB7XG--\r\n"
> request$files
$file
$file$filename
[1] "cantons_4.csv"
$file$content_type
[1] "application/vnd.ms-excel"
$file$offset
[1] 156
$file$length
[1] 161
Hello there is way to update AuthBackendBearer in a production instance?
auth_fun = function(token) {
res = FALSE
try({
res = token %in% allowed_tokens
}, silent = TRUE)
return(res)
}
bearer_auth_backend <- AuthBackendBearer$new(FUN = auth_fun)
I have some user creation and the allowed_tokens changes while new user are added to the database in MongoDB. There is any chance that this "allowed_tokens" update automaticly without restarting the app with AuthBackendBearer$new(FUN = auth_fun) ??
sorry folks, I have zero spare time at the moment. @aavanesy feel free to send PR, I will review and merge. That will be the best way to fix this bug
@TomasAcunaRuz_twitter overall proper Bearer auth is quite more trickier thing that I though when I was creating this auth backend. Typically it involves exchange of JWT tokens and Ouath2/Openid Connect. As for your case you will need to query allowed tokens from mongodb each time you check authentication for a user. And of course restarting app is not something you want to do =)