SDKs overview

Svix provides a suite of Software Development Kits (SDKs) and client libraries designed to facilitate integration with its webhook infrastructure. These SDKs abstract the complexities of direct API calls, enabling developers to send and receive webhooks, manage applications, endpoints, and messages programmatically across various programming languages. By leveraging these libraries, developers can streamline the implementation of reliable webhook delivery and consumption within their applications.

The SDKs handle aspects such as request signing, timestamp verification for incoming webhooks, and secure delivery of outgoing webhooks. This approach aims to reduce the boilerplate code required for common webhook operations and enhance developer experience. Svix categorizes its SDKs into actively maintained official libraries and community-contributed projects, with official documentation providing detailed guides for each supported language.

Official SDKs by language

Svix offers officially supported SDKs for a broad range of popular programming languages. These libraries are maintained directly by Svix and are typically the recommended method for integrating with the Svix platform. Each SDK provides idiomatic interfaces tailored to the specific language's conventions, allowing developers to interact with the Svix API using familiar patterns.

The following table lists the official SDKs, their package names, and typical installation commands:

Language Package/Module Name Installation Command Maturity
Python svix pip install svix Stable
Node.js @svix/svix npm install @svix/svix or yarn add @svix/svix Stable
Ruby svix gem install svix Stable
Go github.com/svix/svix-go go get github.com/svix/svix-go Stable
Java com.svix:svix (Maven) <dependency><groupId>com.svix</groupId><artifactId>svix</artifactId><version>X.Y.Z</version></dependency> Stable
C# Svix dotnet add package Svix Stable
PHP svix/svix composer require svix/svix Stable
Rust svix Add svix = "X.Y.Z" to Cargo.toml Stable
Elixir svix Add {:svix, "~> X.Y"} to mix.exs dependencies Stable

Developers are encouraged to consult the Svix SDKs documentation for the most current versions and detailed installation instructions.

Installation

Installing a Svix SDK typically involves using the package manager specific to the programming language or environment being used. The process generally requires a single command to download and integrate the library into a project.

Node.js

npm install @svix/svix
# or
yarn add @svix/svix

Python

pip install svix

Ruby

gem install svix

Go

go get github.com/svix/svix-go

Java (Maven)

Add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.svix</groupId>
    <artifactId>svix</artifactId&n>
    <version>1.10.0</version> <!-- Replace with the latest version -->
</dependency>

C# (.NET)

dotnet add package Svix

PHP (Composer)

composer require svix/svix

Rust (Cargo)

Add the following to your Cargo.toml file:

[dependencies]
svix = "1.10.0" # Replace with the latest version

Elixir (Mix)

Add the following to your mix.exs file dependencies:

def deps do
  [
    {:svix, "~> 1.10"} # Replace with the latest version
  ]
end

After installation, the SDK can be imported and initialized in your application code using the provided API key. The Svix API keys, including the AUTH_TOKEN, are managed within the Svix dashboard for secure access.

Quickstart example

This quickstart example demonstrates how to initialize the Svix client and send a simple webhook message using the Node.js SDK. Similar patterns apply across other supported languages, with slight variations in syntax.

Node.js Quickstart: Sending a Webhook

First, ensure you have an application created in the Svix dashboard and an associated application ID. You will also need your Svix API key.

import { Svix } from "@svix/svix";

const SVIX_AUTH_TOKEN = process.env.SVIX_AUTH_TOKEN || "YOUR_SVIX_API_KEY";
const APPLICATION_ID = process.env.APPLICATION_ID || "YOUR_APPLICATION_ID";

if (!SVIX_AUTH_TOKEN || !APPLICATION_ID) {
  console.error("Please set SVIX_AUTH_TOKEN and APPLICATION_ID environment variables.");
  process.exit(1);
}

async function sendWebhook() {
  try {
    const svix = new Svix(SVIX_AUTH_TOKEN);

    const message = await svix.message.create(APPLICATION_ID, {
      eventType: "user.created",
      payload: {
        id: "user_123",
        name: "John Doe",
        email: "[email protected]"
      }
    });
    console.log("Webhook message sent successfully:", message.id);

  } catch (error) {
    console.error("Error sending webhook message:", error);
  }
}

sendWebhook();

This example initializes the Svix client with an authentication token and then uses the message.create method to send a new message for a specified eventType (e.g., user.created) to a particular application. The payload contains the actual data to be delivered to the webhook consumers. For broader understanding of webhook event types, refer to generalized webhook concepts on MDN Web Docs.

Receiving and Verifying Webhooks (Node.js)

When an endpoint receives a webhook from Svix, it's crucial to verify its authenticity and integrity. This typically involves checking the svix-id, svix-timestamp, and svix-signature headers.

import { Webhook } from "@svix/svix";
import express from "express";

const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET || "YOUR_WEBHOOK_SECRET"; // Retrieve from Svix dashboard for your endpoint

if (!WEBHOOK_SECRET) {
  console.error("Please set WEBHOOK_SECRET environment variable.");
  process.exit(1);
}

const app = express();
app.use(express.json()); // Middleware to parse JSON body

app.post("/webhooks", async (req, res) => {
  const payload = JSON.stringify(req.body); // Svix expects raw body as string
  const headers = req.headers;

  const svixId = headers["svix-id"];
  const svixTimestamp = headers["svix-timestamp"];
  const svixSignature = headers["svix-signature"];

  if (!svixId || !svixTimestamp || !svixSignature) {
    return res.status(400).send("Missing Svix headers");
  }

  try {
    const wh = new Webhook(WEBHOOK_SECRET);
    const verifiedPayload = wh.verify(payload, {
      "svix-id": svixId,
      "svix-timestamp": svixTimestamp,
      "svix-signature": svixSignature,
    });
    console.log("Webhook verified successfully:", verifiedPayload);
    // Process the event here
    res.status(200).send("OK");
  } catch (err) {
    console.error("Webhook verification failed:", err);
    res.status(400).send("Webhook signature verification failed");
  }
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}`);
});

This receiving example uses an Express.js server to handle incoming POST requests to a /webhooks endpoint. It extracts the necessary Svix headers (svix-id, svix-timestamp, svix-signature) and the raw request body. The Webhook class from the Svix SDK is then used to verify the incoming payload against a secret key configured for the specific webhook endpoint. Successful verification confirms the webhook's origin and integrity, allowing the application to safely process the event data.

Community libraries

In addition to the official SDKs, the Svix ecosystem includes community-contributed libraries and integrations. These libraries often extend functionality, provide bindings for less common languages, or offer specific frameworks/tool integrations not covered by official SDKs. While not officially maintained or supported by Svix, they can be valuable resources for developers working with specific technology stacks.

Developers should exercise diligence when using community-contributed libraries, verifying their maintenance status, security practices, and compatibility with the latest Svix API versions. Checking the project's GitHub repository, issue tracker, and community forums is recommended. For a comprehensive list and links to community projects, refer to the Svix community page within their documentation.

Examples of community contributions might include:

  • Framework-specific integrations (e.g., Django, Ruby on Rails, Laravel webhook handlers).
  • Libraries for languages not covered by official SDKs.
  • Tools for local webhook development and testing.
  • Monitoring or observability integrations for webhook events.

The open-source nature of many such projects allows for direct inspection of their codebases, which can be useful for understanding their implementation details and assessing their suitability for a given project.