1 stable release
1.0.0 | May 2, 2022 |
---|
#1165 in HTTP server
10KB
94 lines
!(image1)https://imgur.com/5qaPfr3.png
actix-web-tonic
actix-web-tonic
is the concurrent runner ofactix-web
+tonic
.- You can build a rich and fast server app using Web + gRPC so easily with the crate.
Usage
- Implement your
actix-web
server same as basically coding, and get the future:
let actix_future = HttpServer::new(|| { App::new().service(...
...brabrabra...
.bind("[::1]:50000").unwrap()
.workers(8) // <- # of workers setting is here in actix-web.
.run(); // <- this type is `Service`, it's an `impl` of `Future`.
- Implement your
tonic
server same as basically coding, and get the future:
let tonic_future = Server::builder().add_service(...
...brabrabra...
...serve(addr); // <- this type is a simple `Future` of `asyncl`.
- Invoke in concurrent both of your actix-web future and your tonic future:
let tonic_worker_threads = 16; // <- # of workers setting is here in tonic.(=# of tokio workers)
let result = actix_web_tonic::invoke(actix_future, tonic_future, tonic_worker_threads);
And then, test your server:
# gRPC:
$ grpcurl -plaintext -import-path ./proto -proto helloworld.proto -d '{"name": "Tonic"}' '[::1]:50001' helloworld.Greeter/SayHello
{
"message": "Hello Tonic!"
}
# Web:
$ curl '[::1]:50000/teapot' -v
* Trying ::1:50000...
* TCP_NODELAY set
* Connected to ::1 (::1) port 50000 (#0)
> GET /teapot HTTP/1.1
> Host: [::1]:50000
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 418 I'm a teapot
< content-length: 23
< date: Sun, 01 May 2022 23:29:41 GMT
<
* Connection #0 to host ::1 left intact
I like a green tea.🍵%
- Want you all of the example?
- => The full example is here: examples/simple/
Motivation and Notes
- I had try implements a single bin process actix-web + tonic service but it was little hard to code for every works. Then, I publish this crate. It will be a good little helps to the
future
of me, and ofcourse you who looks this crate.💕 - Of course, this crate is for servers. If your goal is not to provide a server, you want to complete an applications, you will also need crates for the client side to fight WASM, HTML/CSS and UI/UX.💪
LICENSE
Author
- USAGI.NETWORK / Usagi Ito https://github.com/usagi/
Dependencies
~16–30MB
~500K SLoC