sergio benitez
play

Sergio Benitez sb@sergio.bz 1 Introduction to Rocket 2 Code - PowerPoint PPT Presentation

Sergio Benitez sb@sergio.bz 1 Introduction to Rocket 2 Code Generation in Rocket and Rust 3 Whats Next? 1 Introduction to Rocket Simple, Fast, Type-Safe Web Framework Powered by Rusts Code Generation Facilities Enables


  1. Sergio Benitez sb@sergio.bz

  2. 1 Introduction to Rocket 2 Code Generation in Rocket and Rust 3 What’s Next?

  3. 1 Introduction to Rocket • Simple, Fast, Type-Safe Web Framework • Powered by Rust’s Code Generation Facilities • Enables Secure, Robust Web Applications 2 Code Generation in Rocket and Rust 3 What’s Next?

  4. 1 Introduction to Rocket 2 Code Generation in Rocket and Rust • Demystifying the “Magic” of Code Generation • Present and Future Code Generation APIs 3 What’s Next?

  5. 1 Introduction to Rocket 2 Code Generation in Rocket and Rust 3 What’s Next? • What’s Coming in Future Versions of Rocket • Code Generation at Large

  6. 1 Introduction to Rocket Simple, Fast, Type-Safe Web Framework 2 Code Generation in Rocket and Rust Demystifying the “Magic” of Code Generation 3 What’s Next? What’s Coming in Future Versions of Rocket

  7. Simple, Fast, Type-Safe Web Framework 2 Code Generation in Rocket and Rust 1 Introduction to Rocket Demystifying the “Magic” of Code Generation 3 What’s Next? What’s Coming in Future Versions of Rocket

  8. Rocket is a web framework for Rust that makes it simple to write fast web applications without sacrificing flexibility or type safety.

  9. ⋆ 2,670 Launch! v0.2 v0.3 Dec. 23, 2016 Feb. 06, 2017 Jul. 14, 2017

  10. in production ⋆ 2,670 Launch! v0.2 v0.3 Dec. 23, 2016 Feb. 06, 2017 Jul. 14, 2017

  11. ⋆ 2,670 Launch! v0.2 v0.3 Dec. 23, 2016 Feb. 06, 2017 Jul. 14, 2017

  12. Launch! v0.2 Early 2016 Dec. 23, 2016 Feb. 06, 2017

  13. Rocket is a web framework for Rust that makes it simple to write fast web applications without sacrificing flexibility or type safety.

  14. Routes (Hello, world!) #[get("/")] 1 fn hello() -> &'static str { 2 "Hello, world!" 3 } 4

  15. Routes (Hello, world!) 1 #[get("/")] 1 fn hello() -> &'static str { 2 "Hello, world!" 3 } 4 1 Route Attribute: Description of matching condition.

  16. Routes (Hello, world!) 1 #[get("/")] 1 2 fn hello() -> &'static str { 2 "Hello, world!" 3 } 4 1 Route Attribute: Description of matching condition. 2 Route Handler: Request processing, produces response.

  17. Routes (Hello, world!) 1 #[get("/")] 1 2 fn hello() -> &'static str { 2 "Hello, world!" 3 } 4 1 Route Attribute: Description of matching condition. 2 Route Handler: Request processing, produces response.

  18. Routes (Hello, world!) 1 #[get("/")] 1 2 fn hello() -> &'static str { 2 "Hello, world!" 3 } 4 1 Route Attribute: Description of matching condition. 2 Route Handler: Request processing, produces response.

  19. Routes (Hello, world!) 1 #[get("/")] 1 2 fn hello() -> &'static str { 2 "Hello, world!" 3 } 4 1 Route Attribute: Description of matching condition. 2 Route Handler: Request processing, produces response.

  20. Mounting & Launching #[get("/")] #[get("/")] 1 fn hello() -> &'static str { fn hello() -> &'static str { 2 "Hello, world!" "Hello, world!" 3 } } 4 5 fn main() { 6 rocket::ignite().mount("/", routes![hello]).launch(); 7 } 8 Routes need to be mounted to make Rocket aware .

  21. Mounting & Launching #[get("/")] #[get("/")] 1 fn hello() -> &'static str { fn hello() -> &'static str { 2 "Hello, world!" "Hello, world!" 3 } } 4 5 fn main() { 6 rocket::ignite().mount("/", routes![hello]).launch(); 7 } 8 Mounting namespaces routes according to a root path.

  22. Mounting & Launching #[get("/")] #[get("/")] 1 fn hello() -> &'static str { fn hello() -> &'static str { 2 "Hello, world!" "Hello, world!" 3 } } 4 5 fn main() { 6 rocket::ignite().mount("/hello", routes![hello]).launch(); 7 } 8 Mounting namespaces routes according to a root path.

  23. Mounting & Launching #[get("/")] #[get("/")] 1 fn hello() -> &'static str { fn hello() -> &'static str { 2 "Hello, world!" "Hello, world!" 3 } } 4 5 fn main() { 6 rocket::ignite().mount("/", routes![hello]).launch(); 7 } 8 Mounting namespaces routes according to a root path.

  24. Mounting & Launching #[get("/")] #[get("/")] 1 fn hello() -> &'static str { fn hello() -> &'static str { 2 "Hello, world!" "Hello, world!" 3 } } 4 5 fn main() { 6 rocket::ignite().mount("/", routes![hello]).launch(); 7 } 8 Launch ing starts up the server.

  25. Mounting & Launching #[get("/")] #[get("/")] 1 fn hello() -> &'static str { fn hello() -> &'static str { 2 "Hello, world!" "Hello, world!" 3 } } 4 5 fn main() { 6 rocket::ignite().mount("/", routes![hello]).launch(); 7 } 8 Launch ing starts up the server. (also prints emojis 🚁 )

  26. Mounting & Launching #[get("/")] #[get("/")] 1 fn hello() -> &'static str { fn hello() -> &'static str { 2 "Hello, world!" "Hello, world!" 3 } } 4 5 fn main() { 6 rocket::ignite().mount("/", routes![hello]).launch(); 7 } 8 Launching starts up the server. (also prints emojis 🚁 )

  27. Mounting & Launching #[get("/")] #[get("/")] 1 fn hello() -> &'static str { fn hello() -> &'static str { 2 "Hello, world!" "Hello, world!" 3 } } 4 5 fn main() { 6 rocket::ignite().mount("/", routes![hello]).launch(); 7 } 8

  28. Mounting & Launching #[get("/world")] #[get("/")] 1 fn hello() -> &'static str { fn hello() -> &'static str { 2 "Hello, world!" "Hello, world!" 3 } } 4 5 fn main() { 6 rocket::ignite().mount("/", routes![hello]).launch(); 7 } 8

  29. Mounting & Launching #[get("/sergio")] #[get("/")] 1 fn hello() -> &'static str { fn hello() -> &'static str { 2 "Hello, Sergio!" "Hello, world!" 3 } } 4 5 fn main() { 6 rocket::ignite().mount("/", routes![hello]).launch(); 7 } 8

  30. Rocket is a web framework for Rust that makes it simple to write fast web applications without sacrificing flexibility or type safety.

  31. Dynamic Paths

  32. Dynamic Paths

  33. Dynamic Paths #[get("/<name>/<age>")] 1 fn hello(name: String, age: u8) -> String { 2 format!("Hello, {} year old named {}!", age, name) 3 } 4 Parameters in < brackets > match any text in segment.

  34. Dynamic Paths #[get("/<name>/<age>")] 1 fn hello(name: String, age: u8) -> String { 2 format!("Hello, {} year old named {}!", age, name) 3 } 4 Parameters in < brackets > match any text in segment. • Name in <brackets> must have matching function argument.

  35. Dynamic Paths #[get("/<name>/<age>")] 1 fn hello(name: String, number: u8) -> String { 2 format!("Hello, {} year old named {}!", age, name) 3 } 4 Parameters in < brackets > match any text in segment. • Name in <brackets> must have matching function argument.

  36. Dynamic Paths #[get("/<name>/<age>")] 1 fn hello(name: String, number: u8) -> String { 2 format!("Hello, {} year old named {}!", age, name) 3 } 4 Parameters in < brackets > match any text in segment. • Name in <brackets> must have matching function argument.

  37. Dynamic Paths #[get("/<name>/<age>")] 1 fn hello(name: String, number: u8) -> String { 2 format!("Hello, {} year old named {}!", age, name) 3 } 4 Parameters in < brackets > match any text in segment. • Name in <brackets> must have matching function argument.

  38. Dynamic Paths #[get("/<name>/<age>")] 1 fn hello(name: String, age: u8) -> String { 2 format!("Hello, {} year old named {}!", age, name) 3 } 4 Parameters in < brackets > match any text in segment. • Name in <brackets> must have matching function argument.

  39. Dynamic Paths #[get("/<name>/<age>")] 1 fn hello(name: String, age: u8) -> String { 2 format!("Hello, {} year old named {}!", age, name) 3 } 4 Parameters in < brackets > match any text in segment. • Type of dynamic parameter is declared in handler signature. • Any type implementing FromParam is allowed.

  40. Dynamic Paths #[get("/<name>/<age>")] 1 fn hello(name: String, age: u8) -> String { 2 format!("Hello, {} year old named {}!", age, name) 3 } 4 Parameters in < brackets > match any text in segment. • Handler can only be called if FromParam conversion succeeds.

Recommend


More recommend