Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you give an example? #29

Open
sunbjt opened this issue Dec 5, 2017 · 2 comments
Open

Can you give an example? #29

sunbjt opened this issue Dec 5, 2017 · 2 comments

Comments

@sunbjt
Copy link

sunbjt commented Dec 5, 2017

This package is great! Thanks very much for your excellent work.
I'm confused for passing value from outside into Fiery. The example may be like this:

curl http://127.0.0.1:8080/predict?val=10

The output depends on the input val=10, I want to get(10*2):

{
  "v": 20,
}

Thank you very much for your help.

@sunbjt
Copy link
Author

sunbjt commented Jan 4, 2018

I got the example from https://www.data-imaginist.com/2017/introducing-reqres/. Like this:

library(fiery)
library(reqres)

app <- Fire$new()

app$on('request', function(server, request, ...) {
    response <- request$respond()
    res <- request$query$val
    message(sprintf("Input: %s", res))
    response$body <- jsonlite::toJSON(res*2, auto_unbox = TRUE, pretty = TRUE)
    response$status <- 200L
    response$type <- 'html'
    response
})

app$ignite(showcase = FALSE)

When I run http://127.0.0.1:8080/predict?val=10, the response is [].
But when I run http://127.0.0.1:8080/predict?x&val=3, the response is right.
It may be a bug.

platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          3                           
minor          4.3                         
year           2017                        
month          11                          
day            30                          
svn rev        73796                       
language       R                           
version.string R version 3.4.3 (2017-11-30)
nickname       Kite-Eating Tree  

@LalZzy
Copy link

LalZzy commented May 17, 2018

Hi, Sizhe. When you run http://127.0.0.1:8080/predict?val=10, the url delivered to the program is not always true. I think this is a bug. When the url contains '?', it will become '??' in your program.
In your example, I simply add a line:

library(fiery)
library(reqres)

app <- Fire$new()

app$on('request', function(server, request, ...) {
    response <- request$respond()

    ##print the url it accept
    message(request$url)

    res <- request$query$val
    message(sprintf("Input: %s", res))
    response$body <- jsonlite::toJSON(res*2, auto_unbox = TRUE, pretty = TRUE)
    response$status <- 200L
    response$type <- 'html'
    response
})

app$ignite(showcase = FALSE)

When I run http://127.0.0.1:8080/predict?val=10, it shows that

message: http://127.0.0.1:8080/predict??val=3
message: 

so you can see that the input is not correct, which is the answer why you can not get 3*2 = 6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants