-
Notifications
You must be signed in to change notification settings - Fork 257
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
ws experiment #724
base: main
Are you sure you want to change the base?
ws experiment #724
Conversation
I think this is more interesting. api #* @post /sleeper
#* @get /sleeper
#* @param payload:df
#* @parser json
#* @serializer unboxedJSON
function(payload = matrix(1:8, 2, 4), req) {
a <- rowSums(payload)
req$ws$send("Almost done")
b <- colSums(payload)
req$ws$send("Calculation completed")
list(a, b)
} Using websockets ws <- websocket::WebSocket$new("ws://127.0.0.1:3946/sleeper")
ws$onMessage(function(res) { cat(res$data, "\n") })
ws$send('{"payload":[[1,3,5,7],[2,4,6,8]]}')
ws$close() results > ws <- websocket::WebSocket$new("ws://127.0.0.1:9629/sleeper")
> ws$onMessage(function(res) { cat(res$data, "\n") })
> ws$send('{"payload":[[1,8,5,7],[2,5,6,50]]}')
Almost done
Calculation completed
_status_ 200
_headers_ Content-Type=application/json
_body_ nextmessage
[[21,63],[3,13,11,57]]
> ws$close() Then you can get intermediate response before getting the final response. Still use case to cover, I think this is a good start. |
pr$serve(req, res) | ||
ws$send(paste("_status_", res$status)) | ||
ws$send(paste("_headers_", paste(names(res$headers), unlist(res$headers), sep = "=", collapse = ";"))) | ||
ws$send("_body_ nextmessage") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably makes more sense to only return res$body
in websockets context?
Would websockets bypass cookie or apikey filter? Most likely they should not be enabled by default. |
Related: #723
You get an
Error in wsSend(private$wsObj, msg) : invalid state
when you try to use websockets while a request is being processed by the regular REST API over http.I've yet to find a way to leverage websockets over regular plumbing, this need more thinking.
PR task list:
devtools::document()