A Rust API service using Unkey for API key validation with the Axum framwork.
This example shows how to secure a Rust + Axum API using Unkey for API key management. You'll learn how to protect public and private routes with minimal setup and start authenticating users quickly.
create_key
, read_key
, encrypt_key
and decrypt_key
.1git clone git@github.com:unrenamed/unkey-rust-axum2cd unkey-rust-axum
.env
file in the root directory and populate it with the following environment variables:1PORT=30002UNKEY_ROOT_KEY=your-unkey-root-key3UNKEY_API_ID=your-unkey-api-id
Ensure you replace your-unkey-root-key
and your-unkey-api-id
with your actual Unkey credentials.
1cargo run
The server will start and listen on the port specified in the .env
file (default is 3000
).
1 curl http://localhost:3000/public
1 curl http://localhost:3000/public -H "Authorization: Bearer <YOUR_API_KEY>"
1 curl http://localhost:3000/protected -H "Authorization: Bearer <YOUR_API_KEY>"
2500 verifications and 100K successful rate‑limited requests per month. No CC required.