Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Stefano Borghi
    @stebogit
    however I need to pass a significant amount of data to the script and I don't think using CLI parameters/arguments would work (it would at least be ugly :D)
    now, I think a cleaner solution would be implementing an internal (to the VM running the API) HTTP (or TCP?) server which I can then interface with "standard" URL queries, where I can POST as much data as I like
    Stefano Borghi
    @stebogit
    in my understanding there are two possible options here, Rserve and FastRWeb. However it looks like to me Rserver is TCP service and I'm not sure how to interact with it in PHP, while FastRWeb is a web server that only serves static files
    is the above correct?
    any suggestions?
    in other words, ideally I'd like to set up an internal service that in my app I can interact with via $result = $client->post('http://localhost:12345/myRscript', ['parameter', 'some value']) and get back a (JSON or HTML) string as a result
    Stefano Borghi
    @stebogit
    maybe https://www.rplumber.io is what I was looking for...
    Dmitry Selivanov
    @dselivanov

    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?

    Stefano Borghi
    @stebogit
    ah, wow, that's right. Not sure why but I honestly did not see that...
    how does RestRserve compare to Plumber?
    Dmitry Selivanov
    @dselivanov
    They are both libraries to build REST API. There are some nuances (syntax, performance, etc), but overall you can use any of them.
    Stefano Borghi
    @stebogit
    Thanks @dselivanov!
    Stefano Borghi
    @stebogit
    is there a solution for automatic restart of the server while development?
    like whenever a file changes
    jds-amplify
    @jds-amplify
    hi

    which host/ip the server binds to?See very first example in the readme:

    backend$start(app, http_port = 8080)

    Note that I'm asking about HOST, not the port. I saw the first example, which didn't tell me how to set the host. Thanks.
    (apologies for posting the question as an issue.)
    @stebogit plumber ti limita a solo un thread. Utile durante la fase di sviluppo, ma per production noi l'abbiamo dovuto rimpiazzare con RestRserve.
    jds-amplify
    @jds-amplify
    @dselivanov another comment: by default in wrapping 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.
    Dmitry Selivanov
    @dselivanov

    Note that I'm asking about HOST, not the port

    host is conventional 0.0.0.0

    : 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

    jds-amplify
    @jds-amplify

    host is conventional 0.0.0.0

    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?

    jds-amplify
    @jds-amplify

    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.

    Dmitry Selivanov
    @dselivanov

    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.

    Give it a try, would be nice to hear feedback after that
    Arkadi
    @aavanesy

    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

    Dmitry Selivanov
    @dselivanov
    Hi @Arkadi. You may have as many middleware as you want - just pass ordered list of middlewares to the app constructor.
    As for authentication with token I suggest to follow one of the 'openid connect' (which involves jwt tokens). For simpler cases you might use simple authentication.
    Dmitry Selivanov
    @dselivanov
    However I'm not aware of any mature R PKG which facilitates with openid connect and RestRserve
    Arkadi
    @aavanesy
    Hi all,
    Can you please help me with a request that contains an uploaded file?
    request$get_file("csv") returns NULL
    but the body contains a csv, I can see it
    > 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
    Dmitry Selivanov
    @dselivanov
    I believe you need to run $get_file('cantons_4.csv')
    Arkadi
    @aavanesy
    I attached the Rdata file with the request object in previous message
    >   cnt = request$get_file("cantons_4.csv") # 'csv' from the upload form field
    > cnt
    NULL
    3 replies
    Dmitry Selivanov
    @dselivanov
    @aavanesy yeah, there is a bug here - https://github.com/rexyai/RestRserve/blob/96513b969e1dbcf8e2d14732e0618e607945112e/R/Request.R#L204.
    I will try to fix today-tomorrow. In the meantime you can take a look to the source code to get an idea about how to exctract file.
    Thanks for reporting
    Arkadi
    @aavanesy
    Sounds great. I tried to use the raw_slice function but I am not very proficient with Rcpp...
    Arkadi
    @aavanesy
    @dselivanov still can't figure out a solution. Have you had a chance to check this? I believe Rcpp was updated recently with some major changes and that's why it doesn't work anymore.
    Arkadi
    @aavanesy
    @dselivanov sorry for insisting but is there any chance you checked this? I am in the middle of a big project and this step is crucial...
    I could open a github issue
    Arkadi
    @aavanesy
    I will use a corrected version of this for now idx = seq_len(self$files[[name]]$length) + self$files[[name]]$offset - 1L
    Tomás Acuña Ruz
    @TomasAcunaRuz_twitter

    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) ??

    Dmitry Selivanov
    @dselivanov

    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 =)

    Tomás Acuña Ruz
    @TomasAcunaRuz_twitter
    thanks, I resolve with a SECRET token which work properly !
    Pierrick Kinif
    @pkinif

    Hi all,

    I have a RestRserve API hosted on an EC2 instance on port 8080 (I use docker-compose). I want to set up the HTTPS using Nginx and certbot. I am struggling at that. Any good documentation to point at?

    bowerth
    @bowerth
    Hi, is the project still being maintained? there hasn't been any push to the master branch since 2020...
    Dmitry Selivanov
    @dselivanov
    @bowerth it is! It's just reached stable status. Probably worth to release version 1.0
    @pkinif I would be happy to help. But please don't cross-post here and in github issues.
    Arkadi
    @aavanesy
    @dselivanov I will make a push this week. Very busy as well.
    It is very stable indeed. We use it on a project with hundreds of complex calculations using R + Python/Reticulate scripts and everything is just perfect.
    Pierrick Kinif
    @pkinif

    @pkinif I would be happy to help. But please don't cross-post here and in github issues.

    sure, I will continue in github, thanks for your help!