for rocket@0.4
```rust
extern crate rocket;
use rocket_jwt::jwt;
pub struct UserClaim { id: String, }
fn index() -> String { let userclaim = UserClaim { id: format!("hellorocketjwt"), }; let token = UserClaim::sign(userclaim); println!("{:#?}", UserClaim::decode(token.clone())); token }
fn getueridfromjwt(user: UserClaim) -> String { format!("user id is {}", user.id) }
fn main() { rocket::ignite() .attach(UserClaim::fairing()) .mount("/", routes![index, getueridfromjwt]) .launch(); }
```
| attribute | type | description | default | |----------|------|-------------|---| | | String | jwt secret key, required | | | exp | Int | token expire in seconds | 2663280 (one month) |
cargo run --example rocket-jwt-demo
jwt
token
curl http://localhost:8000
jwt
token
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" http://localhost:8000/uer_id