Comments (6)
there are several options:
Resource::async handler
you can use https://actix.github.io/actix-web/actix_web/struct.Resource.html#method.async
in that case your handle needs to return Stream<Item=Frame>
Http actor
In that case you can define http actor, then you can use HttpContext
to spawn any number of futures of streams.
here is simple example https://github.com/actix/actix-web/blob/master/examples/multipart/src/main.rs#L25
if you need more complex interaction, then you can define Message
's and handle them as actix actor.
here is example how to add stream to your actor's context
https://github.com/actix/actix-web/blob/master/examples/websocket.rs#L33
then you can handle items from this stream in your Handler
https://github.com/actix/actix-web/blob/master/examples/websocket.rs#L49
Api still is not very stable, especially simple async handlers. But actor's Handler
seems works well.
While building SockJS server, I didn't have any problems. also I am working on http/2 support, and it seems no public api changes will be required.
I am open to any suggestions and you are welcome to join !
from actix-web.
Trying to implement using Resource.async. I created a function that I want to have return Stream<Item=Frame> but I'm unsure of how to get a Frame object. It doesn't appear to be public.
I suspect there is something simple I am missing. I'm not using Future yet but it should be easy enough to convert a Future into a stream as needed assuming I'm not misunderstanding what I need to do.
fn with_param(
req: &mut HttpRequest,
_payload: Payload,
state: &(),
) -> impl Stream<Item = actix_web::route::Frame, Error = ()> {
futures::stream::once(Ok(
HttpResponse::builder(StatusCode::OK)
.content_type("text/html")
.body(format!("Hello {}!", req.match_info().get("name").unwrap()))
.unwrap(),
))
}
from actix-web.
let me add example
from actix-web.
Thank you I really appreciate it. Thanks for having patience with me and for putting something as cool as Actix together.
from actix-web.
here is example https://github.com/actix/actix-web/blob/master/examples/basic.rs#L17
but you need to update actix-web to 0.2.1
I think Error=()
is wrong choice.
from actix-web.
Agreed () is most certainly not the correct choice.
Thanks for exposing Frame and for the example. This is exactly what I needed.
from actix-web.
Related Issues (20)
- Call for help with bind_rustls_021 just support one request at the same time HOT 6
- default service not defaulting to the parent scope
- Pending multipart request with angular rxjs HOT 1
- **I want to send the bytes of the playload to the LOG server in the log middleware** HOT 1
- actix-http 3.5 "Prevent compression of zero-sized response bodies" causes delays to close connection HOT 2
- The function app_data of web::ServiceConfig cannot persist HOT 1
- actix-files: Can't handle files with newlines in them
- websocket bug!Cannot complete one websocket client to send a message to another client
- Why is the code below why version 4 cannot access httpserver, but version 3 can? HOT 1
- awc CONNECT method support
- add Proxy-Connection header HOT 3
- Filter out completely impossible characters.
- Add macro for route handler accepting all HTTP methods HOT 13
- Compilation fails when using the latest version of rustls HOT 5
- Add pattern syntax for optional trailing slash
- [How to] Middleware `Response body` manipulation.
- Add support to be able to test the route tree using `match_pattern` and `match_name`. HOT 2
- Connecting to the database from an external network causes a spike in connections HOT 1
- actix-http: Compilation fails HOT 1
- Err(NoWebsocketUpgrade) HOT 1
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 actix-web.