Svix Blog
Published on

New Rust Webhooks Library

Authors

Cover image

It's no secret that we love ❤️ Rust 🦀 at Svix. Our backend is written in Rust, and it's at least partially what makes it possible for us to ensure the correctness of our code, and support the scale that we do.

So it was only natural for us to offer a Rust library for Svix. So what took us so long? Well, we didn't realize that our customers wanted one. It took a few timely nudges from a few customers to finally get it done, and here we are.

How do I use it?

Make sure to install latest Rust library version. It's >=0.59.1 at the time of this writing, but you can check the crate on crates.io for the latest information.

Using it is trivial. All you need to do is instantiate a new API client, and then start using it.

use svix::api::{ApplicationIn, Svix, SvixOptions};

let svix = Svix::new("AUTH_TOKEN".to_string(), None);
let app = svix.application().create(ApplicationIn {
    name: "Application name".to_string(),
    ..ApplicationIn::default()
}).await?;

As for verifying a webhook signature, all you need to do is:

use svix::webhooks::Webhook;

let secret = "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw".to_string();

let mut headers = http::header::HeaderMap::new();
headers.insert("svix-id", "msg_p5jXN8AQM9LWM0D4loKWxJek");
headers.insert("svix-timestamp", "1614265330");
headers.insert("svix-signature", "v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE=");

let payload = b"{\"test\": 2432232314}";

let wh = Webhook::new(secret)?;
wh.verify(&payload, &headers)?;
// returns Ok on success, Err otherwise

Where can I find the documentation?

This library, like the rest of our libraries, is fully documented. If you are interested, you can also take a look at the library's source code.

For the more tutorial like version of the docs, please refer to the Svix documentation, and for full API documentation, please refer to the Svix API reference.

Reporting issues and making suggestions

The library is already been used by some of our customers (and us), and has been tested to work. Additionally, with Rust being Rust, it comes with high assurances that things remain this way. We run dependency security scans, clippy, and disallow unsafe, so you can use it with ease.

This library however, is still new. If you spot anything wrong, please open a ticket on Github, or let us know via email or Slack.

Coming next

We have a lot more in the works that we'll share in upcoming updates, stay tuned! If you have any thoughts or suggestions regarding what we should work on next, please join the Svix Slack and let us know!

This is it for this update, but make sure to follow us on Twitter, Github or RSS for the latest updates for the Svix webhook provider, or join the discussion on our community Slack.