Building Web APIs with Rust

State of the Union

Rainer Stropek | @rstropek@fosstodon.org |Β  @rstropek

Introduction

Rainer Stropek

  • Passionate software developers for 25+ years
    Β 
  • Microsoft MVP, Regional Director
    Β 
  • Trainer, Teacher, Mentor
    Β 
  • πŸ’• community

Why? How?

Why This Session?

  • Rust πŸ¦€ is becoming more and more popular
    • People from other languages/platforms are coming on board
    • Rust is used in more areas of software development (e.g. APIs)
      Β 
  • Many Web API-related frameworks for Rust
    • Where to start?
    • What to use?
      Β 
  • Guide through Rust's rich and diverse web API ecosystem πŸŒ‚
    • No deep dive, no exhaustive market analysis, an overview
    • Share personal experiences and opinions
    • Provide a starting point for a deeper, project-specific research

How Did I Go About it?

  • A personal selection of four web API frameworks for Rust
    • More platforms/components can be found here and here
      Β 
  • My selection criteria
    • Widely used (huge number of downloads according to crates.io)
    • Feature-rich for developing RESTful web APIs
    • Based on tokio
    • Builds with stable Rust
    • Personal interests and preferences
      Β 
  • If your favorite framework is missing, I apologize
    • We only have limited timeβŒ›
    • Not mentioning a framework does notΒ say anything about its quality!

Agenda

fn main() {
    for framework in ["Actix Web", "Rocket", "Warp", "Axum"] {
        quick::intro(framework);
        look_at::some_code(framework);
        personal::statement(framework);
    }
    
    summary::<closing>();
}
  • Simple API for todo list implemented for all frameworks

About Actix Web

  • Well-established, well maintained
    • Exists for many years, with new releases every few months
    • Currently in version 4.3
    • Feature-rich (including WebSockets)
      Β 
  • Known to be fast ⚑
    • I did not do benchmarks
    • Benchmarks depend on many factors
    • However, results in Techempower Benchmarks are impressive πŸ‘πŸ»

Demo
Time!

My Thoughts About Actix Web

  • Easy to learn
    • Experienced web developer? You will feel at home pretty quickly
      Β 
  • I like the API and the programming model
    • Everything is typed
      Β 
  • Documentation πŸ‘πŸ»
    • Documentation is available
    • Large selection of examples for various use-cases
      ​
  • So?
    • Not my personal favorite, but I would enjoy doing a project with it

About Rocket

  • Well-established, well maintained
    • Exists for many years, quite long since the last non-RC version
    • Currently in version 0.4.10, but 0.5.0-rc.2 available
    • Feature-rich (including Diesel support, but no WebSockets)
      Β 
  • Claims to be simple, "batteries included" - which it is on my opinion
    • Also claims to be fast
    • Benchmarks say it is a little bit slower than the others
      (see here and here)

Demo
Time!

My Thoughts About Rocket

  • Easy to learn, even easier than Actix Web
    • Experienced web developer? No problem getting started!
      Β 
  • I like the API and the programming model
    • Everything is typed, but you shouldn't be allergic to macros πŸ˜‰
      Β 
  • Documentation πŸ‘πŸ»πŸ‘πŸ»
    • Documentation is available and quite detailed (incl. 0.5 RC)
    • Large selection of examples for various use-cases
      ​
  • So?
    • Used it, πŸ’— it
    • Eagerly awaiting 0.5 and following versions

Warp

About Warp

  • Less active in recent time
    • Currently in version 0.3.3
      Β 
  • Different benchmark results
  • Quite a different approach
    • Very different from the first two frameworks you saw
    • Everything based on so-called filters
    • Curious? Let's take a look

Demo
Time!

My Thoughts About Warp

  • Interesting πŸ€”, intellectually challenging for me
    • I have seen quite a few frameworks, but Warp's filters are new to me
      Β 
  • Personally, I do not like the programming model and API so much
    • Super long and complex types make working with Warp difficult
      Β 
  • Documentation is available but could be enhanced
    • Primarily API documentation, not so much conceptual docs
    • Examples are available, fill some gaps of the docs
      ​
  • So?
    • Interesting, but personally I would not use it in a new project

Axum

About Axum

  • Rather young, but getting quite some attention
    • New versions every few months
    • Currently in version 0.6.7 available
    • Relies heavily on tower/tower-http, no custom middleware system
      Β 
  • No Macros πŸ™€
    Β 
  • Seems to be fast ⚑

Demo
Time!

My Thoughts About Axum

  • My current favorite in terms of Rust web API frameworks
    • πŸ’— the API
    • πŸ’— the tight integration with other Tokio crates
      Β 
  • Documentation is available but could be enhanced
    • Primarily API documentation, not so much conceptual docs
    • Large and very helpful selection of examples for various use-cases
      Β 
  • So?
    • Looking forward to doing first real-world projects with it

What about...

Spin

Demo
Time!

My Thoughts About Spin

What an awesome future 🀩!

But a tiny bit too early for production πŸ˜‰

So?

So?

  • You have choices πŸ˜€
    • You must make a choice πŸ€”
      ​
  • Rust for web API development?
    • Definitely works!
      ​
  • Are we at par with other platforms (e.g. ASP.NET Core)?
    • No, not yet. They have more features and offer similar perf.
    • Sweet spot: Web APIs that benefit from Rust's unique features
      (e.g. performance, resource efficiency, featureful language)
      ​
  • Most importantly: Is it fun? Is it enjoyable?
    • Oh yeah, it definitely is πŸ₯³πŸŽŠ

Building Web APIs with Rust

Q&A

Rainer StropekΒ | @rstropek@fosstodon.org |Β  @rstropek