ws experiment#724
Draft
meztez wants to merge 4 commits into
Draft
Conversation
Collaborator
Author
|
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. |
meztez
commented
Dec 23, 2020
| 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") |
Collaborator
Author
There was a problem hiding this comment.
It probably makes more sense to only return res$body in websockets context?
Collaborator
Author
|
Would websockets bypass cookie or apikey filter? Most likely they should not be enabled by default. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #723
You get an
Error in wsSend(private$wsObj, msg) : invalid statewhen 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()