2018-03-21 15:46:27 -07:00
|
|
|
# Actix-web ProtoBuf [](https://travis-ci.org/actix/actix-protobuf) [](https://codecov.io/gh/actix/actix-protobuf) [](https://crates.io/crates/actix-protobuf) [](https://gitter.im/actix/actix?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
|
|
|
|
|
|
Protobuf support for actix-web framework.
|
|
|
|
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
```rust,ignore
|
|
|
|
use actix_web::*;
|
|
|
|
use actix_protobuf::*;
|
|
|
|
use futures::Future;
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Message)]
|
|
|
|
pub struct MyObj {
|
|
|
|
#[prost(int32, tag="1")]
|
|
|
|
pub number: i32,
|
|
|
|
#[prost(string, tag="2")]
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn index(req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
|
|
|
req.protobuf()
|
|
|
|
.from_err() // convert all errors into `Error`
|
|
|
|
.and_then(|val: MyObj| {
|
|
|
|
println!("model: {:?}", val);
|
|
|
|
Ok(httpcodes::HTTPOk.build().protobuf(val)?) // <- send response
|
|
|
|
})
|
|
|
|
.responder()
|
|
|
|
}
|
|
|
|
```
|