Comments (10)
coming up with an ugly hack for websocket ...
import org.http4s.server.websocket._
import org.http4s.websocket.WebsocketBits._
val src = Process.constant("test").toSource.zipWithIndex.map({ case (msg, i) => Text(s"$msg - $i") })take(20)
val snk = Process.halt
// unfortunately websocketkey and websocket case class are both defined in a protected scope that as a user cannot access
val attrs = WS(Exchange(src, snk)).run.attributes.entries.toList
attrs.foldLeft(NotImplemented("this is a websocket route"))(_.withAttribute(_))
Besides exposing too many internal logic, this solution does not allow response evaluated in a separate thread pool. In normal HttpService, I can use Task.fork to easily run the response in a different thread pool, but with rho dsl, there seems to be no easy to achieve the same effect.
from rho.
I have given no consideration to websockets in rho as of yet.
The problem shouldn't be the Task
but the Response
: who deals in Result
s to keep some compile time information around for use in swagger generation etc, which is just a wrapper around Response
with some extra type information.
from rho.
@shengc, I have a PR to address this, but I'm not sure when it will hit a release. In the intrum, you could copy the ResultMatcher
code and bring the implicit into scope manually.
from rho.
I think I got what you mean. I have rewritten the solution I came up with, which now seems more reasonable ...
Task.fork {
import org.http4s.server.websocket._
import org.http4s.websocket.WebsocketBits._
val src = Process.constant("test").toSource.zipWithIndex.map({ case (msg, i) => Text(s"$msg - $i") })take(20)
val snk = Process.halt
WS(Exchange(src, snk)).flatMap(_.attributes.entries.foldLeft(NotImplemented("this is a websocket route"))(_.withAttribute(_)))
}
from rho.
@bryce-anderson, yes that result matcher definitely is helpful :-)
from rho.
This raises another problem though. Look at this example,
GET / "number" +? param[Int]("num") |>> { (num: Int) =>
if (num < 0) BadRequest("num <= 0 :-(")
else WS(Exchange(Process.constant("test").take(num).map(Text(_)), Process.halt))
}
The implicits get messed up in this case, since BadRequest
does not get resolved to a Task[Response]
. The only workaround I have for this is to explicitly use org.http4s.dsl.BadRequest(...)
so that an implicit ResultMatcher[Response]
can be resolved. It is definitely an unpleasant hack, wondering if there is a more natural way to address this ?
from rho.
There is no easy way to make the types unify there. What you've done is the best we can do with the current state of affairs. To make it better, rho will need to get a first class notion of WS
.
from rho.
I do remember another way you can make this work, but you lose any swagger information (if you were using it at all): try BadRequest.pure("num <= 0 :-(")
. that will make a Task[Response]
instead of a Task[Result]
and will match the WS
result type.
from rho.
Thanks :) Does swagger support websocket anyway ?
from rho.
Nope.
On Wed, Jul 15, 2015 at 8:57 PM, Mianwo [email protected] wrote:
Thanks :) Does swagger support websocket anyway ?
—
Reply to this email directly or view it on GitHub
#79 (comment).
from rho.
Related Issues (20)
- Provide example using the Swagger UI Webjar HOT 1
- Got Error with http4s-scala-xml HOT 2
- NoSuchMethodError from rho 0.20.0-M1 HOT 2
- StringParser for value classes HOT 4
- Broken Links/URLs in `README.md` in branch `master` HOT 1
- Where is RhoService? HOT 2
- Feature Idea: Serving swagger in YAML
- Feature Idea: Customisable generic type names
- Is it possible to disable swagger.json endpoint and generate a plain json?
- Release v0.21.0 with swagger webjar implementation HOT 2
- Simple or-path produces incorrect tags HOT 1
- Getting 405 Method Not Allowed from combined routes HOT 3
- Demo example doesn't work HOT 1
- Non-class Scala types break TypeBuilder
- Logger Options in RhoRoutes
- Publish scala 3 artifacts HOT 3
- Getting 405 Method Not Allowed from combined routes with authentication
- Assembly doesn't like CollectionConverters
- Http4s, Scala, and main dependencies update HOT 3
- Maintainers wanted HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rho.