| Crates.io | clerk-fapi-rs |
| lib.rs | clerk-fapi-rs |
| version | 0.2.0 |
| created_at | 2024-11-29 09:09:12.356867+00 |
| updated_at | 2025-10-16 17:59:03.052724+00 |
| description | An unofficial Rust SDK for the Clerk REST Frontend API |
| homepage | https://github.com/Nipsuli/clerk-fapi-rs/ |
| repository | https://github.com/Nipsuli/clerk-fapi-rs/ |
| max_upload_size | |
| id | 1465320 |
| size | 1,556,707 |
An unofficial Rust SDK for the Clerk REST Frontend API.
Works and is used in production. But historically there has been some mismatches with the type definitions and actual behavior, and I haven't used all endpoints, so if you run into issues open an issue or pr.
Can be used in browsers or non browser environments.
This crate is quite thin wrapper on top of the REST Frontend API. Clerk is a
statefull client exposing the full Clerk FAPI methods via Clerk::get_fapi_client.
Clerk keeps the client state updated by piggypagging the requests with the current
client state. The methods in the ClerkFapiClient will unwrap the requests and
return only the core response and update the client state in Clerk stcuct.
The src/apis and src/models are generated based on the fapi_swagger.json.
There seems to have been small issues in the clerk API spec and it has not always
reflected the reality in all of the cases. Those cases where I've run into are
fixed by hand. The models and api methods are also exported so those can be used
directly as well.
By default the state is stored in in HashMap but if one wants to add some
persistent state, example to allow offline state, one can provide anything
that implments the clerk_fapi_rs::configuration::Store trait.
Clerk allows to pass in listere callbacks that are calld
The type of lister:
pub type Listener =
Arc<dyn Fn(Client, Option<Session>, Option<User>, Option<Organization>) + Send + Sync>;
There are only few convenience methods provided directly on the Clerk:
get_token to get session token that can be used to authenticate backend callssign_out to, well, sign outset_active to activate session or organization in sessionAnd to read current state there are helper acccess methods:
Clerk::environment() for the current Clerk instance configsClerk::client() to access full ClientClientClerk::session() to access currently active session parsed from ClientClientClerk::user() to access current user parsed from ClientClientClerk::organization() to access current organization parsed from ClientClientuse clerk_fapi_rs::{clerk::Clerk, configuration::ClerkFapiConfiguration};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let public_key = todo!("Load the way you want");
// Init configuration
let config = ClerkFapiConfiguration::new(
public_key, // String
None, // proxy
None, // domain
)?;
// Or in browser
let config = ClerkFapiConfiguration::new_browser(
public_key, // String
None, // proxy
None, // domain
)?;
// Or with store
let config = ClerkFapiConfiguration::new_with_store(
public_key, // String
None, // proxy
None, // domain
Some(Arc::new(my_clerk_store)),
None, // store_prefix
ClientKind::NonBrowser,
)?;
// Initialize Clerk client
let clerk = Clerk::new(config);
// Load client, it loads the Environment and Client from API
clerk.load().await?;
// If one uses persisted store and want to use cached values
clerk.load(true).await?;
// Get fapi client
let fapi = clerk.get_fapi_client();
// ... do calls with fapi
}
fapi_swagger.jsonopenapi-generator generate -g rust -i fapi_swagger.json \
--global-property models,apis,apiTests=false,modelTests=false,apiDocs=false,modelDocs=false
PR are welcome.
With cargo-release