• Stars
    star
    1,707
  • Rank 27,339 (Top 0.6 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An easy-to-use Rust framework for building robust and performant APIs
pavex
Re-imagining backend development in Rust

What is Pavex?

Pavex is a new framework to build APIs with Rust.

Pavex aims to have it all: great ergonomics and high performance.
The same productivity boost of Ruby on Rails, Spring or ASP.NET Core.
As fast as a handwritten solution that strips away all abstractions.

Pavex takes a significantly different approach compared to the current generation of Rust web frameworks: you can think of Pavex as a specialised compiler for building Rust APIs.
It takes as input a high-level description of what your application should do, a Blueprint:

pub fn app_blueprint() -> Blueprint {
    let mut bp = Blueprint::new();
    bp.constructor(f!(crate::http_client), Lifecycle::Singleton);
    bp.constructor(f!(crate::extract_path), Lifecycle::RequestScoped);
    bp.constructor(f!(crate::logger), Lifecycle::Transient);
    bp.route(GET, "/home", f!(crate::stream_file));
    bp
}

It generates as output a standalone API server SDK crate, behaving according to your specification, ready to be configured and launched.

Great error messages

Pavex operates at the right level of abstractionβ€”it understands the specific challenges and requirements of API development.
The intermediate code generation step (Blueprint -> runtime code) allows Pavex to perform in-depth static analysis. Potential issues are caught at compile-time with an informative error message:

ERROR:
  Γ— `app::get_home` is trying to extract route parameters using `RouteParams<HomeRouteParams>`.
  β”‚ Every struct field in `app::HomeRouteParams` must be named after one of the route parameters 
  | that appear in `/address/:address_id/home/:home_id`:
  β”‚ - `home_id`
  β”‚ - `address_id`
  β”‚
  β”‚ There is no route parameter named `street_id`, but there is a struct field named
  β”‚ `street_id` in `app::HomeRouteParams`. This is going to cause a runtime error!
  β”‚
  β”‚     ╭─[src/lib.rs:43:1]
  β”‚  43 β”‚     ));
  β”‚  44 β”‚     bp.route(GET, "/home/:id", f!(crate::get_home));
  β”‚     Β·                                ───────────┬──────
  β”‚     Β·             The request handler asking for `RouteParams<app::HomeRouteParams>`
  β”‚  45 β”‚     
  β”‚     ╰────
  β”‚   help: Remove or rename the fields that do not map to a valid route parameter.

Compile-time dependency injection

Your Blueprint tells Pavex:

  • What routes should be exposed;
  • What components can be built, what inputs they need and what is their lifecycle;
  • How to handle errors.

Pavex uses this information to perform compile-time dependency injection.

Each endpoint gets its own call graph and Pavex makes sure to exclusively build what is required to invoke every single endpoint, avoiding unnecessary computations.

flowchart TB
    handler["app::stream_file(Pathbuf, Logger, &Client)"]
    client[Client]
    logger["logger() -> Logger"]
    state[ServerState]
    path["extract_path(&RequestHead)->PathBuf"]
    request[RequestHead]

    state --> client
    client --&--> handler
    logger --> handler
    path --> handler
    request --&--> path

You write straight-forward Rust, Pavex takes care of assembling together all the components.

Project status

Pavex is under active development and far from being ready for hobby or production usage.
It has not yet been released on crates.io and you can expect breaking changes on every commit to the main branch.

We are aiming for an alpha release by the end of summer 2023.

We publish project updates every 4 weeks:

Examples

You can see Pavex at work in the /examples folder:

In examples/skeleton/blueprint.ron you can have a peek at what the Blueprint looks like when serialized.

Architectural Overview

If the section above was enough to get you intrigued, you can check out the architectural deep-dive in ARCHITECTURE.md to learn how Pavex works under the hood.

Contributing

This project is not open to unsolicited code contributions (for the time being).
If you want to play around with it, you can find instructions in CONTRIBUTING.md.

License

Licensed under the Apache License, Version 2.0. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

More Repositories

1

zero-to-production

Code for "Zero To Production In Rust", a book on API development using Rust.
Rust
5,631
star
2

cargo-chef

A cargo-subcommand to speed up Rust Docker builds using Docker layer caching.
Rust
1,706
star
3

build-your-own-jira-with-rust

A test-driven workshop to learn Rust building your own JIRA clone!
Rust
937
star
4

wiremock-rs

HTTP mocking to test Rust applications.
Rust
618
star
5

tracing-actix-web

Structured logging for actix-web applications.
Rust
229
star
6

ndarray-koans

Material for "ML Introduction to ndarray" workshop at RustFest 2019.
Jupyter Notebook
110
star
7

biscotti

A Rust library for managing HTTP cookies.
Rust
109
star
8

bunyan

A CLI to pretty print logs in bunyan format. A Rust port of the original JavaScript bunyan CLI.
Rust
92
star
9

tracing-bunyan-formatter

A Layer implementation for tokio-rs/tracing providing Bunyan formatting for events and spans.
Rust
82
star
10

cargo-px

A cargo subcommand that extends cargo's capabilities when it comes to code generation.
Rust
50
star
11

actix-web-flash-messages

A (flash) message framework for actix-web. A port to Rust of Django's message framework.
Rust
46
star
12

multipeek

An iterator adapter to peek at future elements without advancing the cursor of the underlying iterator.
Rust
26
star
13

clustering-benchmarks

Benchmarks `linfa` against `scikit-learn` on a clustering task.
Jupyter Notebook
25
star
14

tracing-panic

A custom panic hook to capture panic info in your telemetry pipeline
Rust
18
star
15

cargo-manifest

Fork to fix some serialization issues.
Rust
12
star
16

jlox-rs

A Rust version of the jlox interpreter from the "Crafting Interpreters" book.
Rust
9
star
17

cargo-like-utils

A collection of utils (shell, styling, locking) to write CLIs that behave similarly to `cargo`
Rust
5
star
18

pavex-project-template

A starter template for a new Pavex project
Rust
3
star
19

LukeMathWalker

2
star
20

reqwest-timeout-minimum-reproducible-example

Minimal reproducible example for a timeout issue with reqwest.
Rust
2
star
21

lukemathwalker.github.io

Personal website.
HTML
1
star
22

iaml-iwildcam2019

Python
1
star
23

tracing-min

Minimum example to reproduce core dump.
Rust
1
star
24

actix-web-minimal-error-example

A minimal reproducible example of issues with actix-web's error handling logic.
Rust
1
star