Web frameworks

Before we begin exploring actix-web, we need to get some motivation as to why we need web frameworks in the first place. The web, as many of us know, is a complex, evolving space. There are lots of details to take care of when writing web applications. You need to set up routing rules and authentication policies. On top of that, as applications evolve, there are best practices and similar patterns that one will have to repeat implementing, if you're not using a web framework.

It's quite tedious having to reinvent these foundational attributes of web applications every time you want to build a web application yourself. A concrete example is when you are providing different routes in your application. In a web application built from scratch, you would have to parse the resource path from the request, do some matching on it, and act on the request. A web framework automates the matching of routes and route handlers by providing DSLs to allow you to configure routing rules in a cleaner way. Web frameworks also abstract all the best practices, common patterns, and idioms around building web applications, and give developers a head start, allowing them to focus on their business logic rather than reinventing solutions for problems that has already been solved.

The Rust community has seen a lot of web frameworks in the works, lately such as Tower, Tide, Rocket, actix-web, Gotham, and so on. At the time of writing this book, the most feature-rich and active frameworks are Rocket and actix-web. While Rocket is quite concise and a polished framework, it requires a nightly version of the Rust compiler. This restriction will soon be removed, though, as the APIs that Rocket depends on get stabilized. Its direct competitor at the moment is actix-web, which runs on stable Rust and is quite close to the ergonomics that are provided by the Rocket framework. We will be covering actix-web next.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset