@@ -17,48 +17,69 @@ This library requires stable/beta Rust.
1717
1818## Installation
1919
20- ``` toml
21- [dependencies ]
22- line-bot-sdk-rust = " 1.0.0"
20+ ``` bash
21+ $ cargo add line-bot-sdk-rust
2322```
2423
25- If you use ` rocket support ` .
24+ ## Web framework support
25+
26+ Extract ` x-line-signature ` from the request header.
27+
28+ ### Use ` rocket ` framework
2629
2730``` toml
2831[dependencies .line-bot-sdk-rust ]
2932version = " 1.0.0"
3033features = [" rocket_support" ]
3134```
3235
33- If you use ` actix_web support ` .
36+ ``` rust
37+ use line_bot_sdk_rust :: support :: rocket :: Signature ;
38+ use rocket :: {http :: Status , post};
39+
40+ #[post(" /callback" , data = " <body>" )]
41+ async fn world (signature : Signature , body : String ) -> (Status , & 'static str ) {
42+ ...
43+ }
44+ ```
45+
46+ ### Use ` actix_web ` framework
3447
3548``` toml
3649[dependencies .line-bot-sdk-rust ]
3750version = " 1.0.0"
3851features = [" actix_support" ]
3952```
4053
54+ ``` rust
55+ use actix_web :: {post, web, Error , HttpResponse };
56+ use line_bot_sdk_rust :: support :: actix :: Signature ;
57+
58+ #[post(" /callback" )]
59+ async fn callback (signature : Signature , bytes : web :: Bytes ) -> Result <HttpResponse , Error > {
60+ ...
61+ }
62+ ```
63+
4164## Configuration
4265
4366``` rust
44- extern crate line_bot_sdk_rust as line;
45- use line :: messaging_api :: apis :: configuration :: Configuration ;
67+ use line_bot_sdk_rust :: client :: LINE ;
4668use std :: env;
4769
4870fn main () {
4971 let access_token : & str =
50- & env :: var (" LINE_CHANNEL_ACCESS_TOKEN" ). expect (" Failed getting LINE_CHANNEL_ACCESS_TOKEN" );
72+ & env :: var (" LINE_CHANNEL_ACCESS_TOKEN" ). expect (" Failed to get LINE_CHANNEL_ACCESS_TOKEN" );
5173
52- let mut conf = Configuration :: default ();
53- conf . bearer_access_token = Some (access_token . to_string ());
74+ let line = LINE :: new (access_token . to_string ());
5475}
5576```
5677
5778## How to use
5879
5980The LINE Messaging API uses the JSON data format.
6081
61- Parse body (` &str ` ) into Result<CallbackRequest, serde_json::Error>.
82+ Example. Parse body (` &str ` ) into Result<CallbackRequest, serde_json::Error>.
6283
6384``` rust
6485let request : Result <CallbackRequest , serde_json :: Error > = serde_json :: from_str (body );
@@ -86,7 +107,7 @@ $ cd examples
86107$ cargo run --bin rocket
87108```
88109
89- source: [ rocket example] ( ./examples/rocket /src/main.rs )
110+ source: [ rocket example] ( ./examples/rocket_example /src/main.rs )
90111
91112### with actix_web framework
92113
@@ -95,7 +116,7 @@ $ cd examples
95116$ cargo run --bin actix_web
96117```
97118
98- source: [ actix_web example] ( ./examples/actix_web /src/main.rs )
119+ source: [ actix_web example] ( ./examples/actix_web_example /src/main.rs )
99120
100121## Contributing
101122
0 commit comments