15 releases

0.3.1 Jul 7, 2024
0.3.0 May 16, 2024
0.2.3 Jan 16, 2024
0.1.9 Dec 5, 2023
0.1.5 Apr 24, 2023

#55 in HTTP server

Download history 209/week @ 2024-03-25 246/week @ 2024-04-01 275/week @ 2024-04-08 97/week @ 2024-04-15 245/week @ 2024-04-22 82/week @ 2024-04-29 256/week @ 2024-05-06 337/week @ 2024-05-13 179/week @ 2024-05-20 150/week @ 2024-05-27 334/week @ 2024-06-03 214/week @ 2024-06-10 64/week @ 2024-06-17 123/week @ 2024-06-24 258/week @ 2024-07-01 209/week @ 2024-07-08

666 downloads per month
Used in 2 crates

MIT license

475KB
10K SLoC

crates.io download count badge

A official community-maintained Clerk SDK for Rust

For more detailed documentation, please reference the below links:

This SDK is updated frequently to keep up with any changes to the actual Clerk API. If you see anything that needs updated or is not inline with the official Clerk api, please open an issue!

Examples

Checkout examples in the /examples directory

Using a traditional http request to a valid clerk endpoint:

use tokio;
use clerk_rs::{clerk::Clerk, ClerkConfiguration, endpoints::ClerkGetEndpoint};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = ClerkConfiguration::new(None, None, Some("sk_test_key".to_string()), None);
    let client = Clerk::new(config);

    let res = client.get(ClerkGetEndpoint::GetUserList).await?;

    Ok(())
}

Using a clerk-rs method:

use tokio;
use clerk_rs::{clerk::Clerk, ClerkConfiguration, apis::emails_api::Email};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = ClerkConfiguration::new(None, None, Some("sk_test_key".to_string()), None);
    let client = Clerk::new(config);

    Email::create(&client, Some(your_clerk_email));

    Ok(())
}

Protecting a actix-web endpoint with Clerk.dev:

With the actix feature enabled:

use actix_web::{web, App, HttpServer, Responder};
use clerk_rs::{validators::actix::ClerkMiddleware, ClerkConfiguration};

async fn index() -> impl Responder {
    "Hello world!"
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        let config = ClerkConfiguration::new(None, None, Some("your_secret_key".to_string()), None);
        App::new()
            .wrap(ClerkMiddleware::new(config, None, true))
            .route("/index", web::get().to(index))
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
}

Protecting a axum endpoint with Clerk.dev:

With the axum feature enabled:

use axum::{routing::get, Router};
use clerk_rs::validators::axum::ClerkLayer;
use clerk_rs::ClerkConfiguration;
use std::net::SocketAddr;

async fn index() -> &'static str {
    "Hello world!"
}

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let config: ClerkConfiguration = ClerkConfiguration::new(None, None, Some("your_secret_key".to_string()), None);
    let app = Router::new().route("/index", get(index)).layer(ClerkLayer::new(config, None, true));
    let addr = SocketAddr::from(([0, 0, 0, 0], 8080));
    let listener = tokio::net::TcpListener::bind(addr).await?;
    axum::serve(listener, app).await
}

Roadmap

  • Support other http clients along with the default reqwest client (like hyper)
  • Tokio and async-std async runtimes for hyper clients
  • Optional reqwest blocking client
  • Support authorization via __session cookie on same-origin
  • Add validator support for axum, rocket, warp

Production users


Dependencies

~12–28MB
~525K SLoC