Starter Kit with Unkey API Authentication
This Ruby on Rails starter kit demonstrates how to implement API key authentication with Unkey. Learn to protect public and private routes easily and authenticate users quickly.
Note: This application uses the Unkey API directly since there is currently no official SDK available for Ruby on Rails, allowing for a hands-on approach to API integration.
This project is built using Ruby 3.2.2 and Rails 7.2.1. Check the Rails documentation for more details on version compatibility.
create_key
, read_key
, encrypt_key
and decrypt_key
.Clone the repository to your local machine:
1git clone git@github.com:unrenamed/unkey-rails2cd unkey-rails
Create a .env
file in the root directory and populate it with the following environment variables:
1UNKEY_API_ID=your-unkey-api-id
Ensure you replace your-unkey-api-id
with your actual Unkey credentials.
Start the server:
1rails server
The server will start and listen on the 3000
port.
Test the public route as a guest:
1curl http://localhost:3000/public
Test the public route as an authorized user by passing the API key in the header:
1curl http://localhost:3000/public -H "Authorization: Bearer <YOUR_API_KEY>"
Test the protected route, which requires valid authorization:
1curl http://localhost:3000/protected -H "Authorization: Bearer <YOUR_API_KEY>"
2500 verifications and 100K successful rate‑limited requests per month. No CC required.