@@ -17,48 +17,69 @@ This library requires stable/beta Rust.
17
17
18
18
## Installation
19
19
20
- ``` toml
21
- [dependencies ]
22
- line-bot-sdk-rust = " 1.0.0"
20
+ ``` bash
21
+ $ cargo add line-bot-sdk-rust
23
22
```
24
23
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
26
29
27
30
``` toml
28
31
[dependencies .line-bot-sdk-rust ]
29
32
version = " 1.0.0"
30
33
features = [" rocket_support" ]
31
34
```
32
35
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
34
47
35
48
``` toml
36
49
[dependencies .line-bot-sdk-rust ]
37
50
version = " 1.0.0"
38
51
features = [" actix_support" ]
39
52
```
40
53
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
+
41
64
## Configuration
42
65
43
66
``` 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 ;
46
68
use std :: env;
47
69
48
70
fn main () {
49
71
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" );
51
73
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 ());
54
75
}
55
76
```
56
77
57
78
## How to use
58
79
59
80
The LINE Messaging API uses the JSON data format.
60
81
61
- Parse body (` &str ` ) into Result<CallbackRequest, serde_json::Error>.
82
+ Example. Parse body (` &str ` ) into Result<CallbackRequest, serde_json::Error>.
62
83
63
84
``` rust
64
85
let request : Result <CallbackRequest , serde_json :: Error > = serde_json :: from_str (body );
@@ -86,7 +107,7 @@ $ cd examples
86
107
$ cargo run --bin rocket
87
108
```
88
109
89
- source: [ rocket example] ( ./examples/rocket /src/main.rs )
110
+ source: [ rocket example] ( ./examples/rocket_example /src/main.rs )
90
111
91
112
### with actix_web framework
92
113
@@ -95,7 +116,7 @@ $ cd examples
95
116
$ cargo run --bin actix_web
96
117
```
97
118
98
- source: [ actix_web example] ( ./examples/actix_web /src/main.rs )
119
+ source: [ actix_web example] ( ./examples/actix_web_example /src/main.rs )
99
120
100
121
## Contributing
101
122
0 commit comments