Implement API key verification in your Koa apps
This simple Koa.js application demonstrates how to implement API key verification using the Unkey service. The application has both public and protected routes, with the protected route requiring a valid API key.
API ID
.access-unkeyed-route
withAuth
permission for the role.Clone this repository:
1git clone https://github.com/harshsbhat/unkey-koa.git2cd unkey-koa
Install the required dependencies
1npm install
Setup env variables. cp .env.example .env
1UNKEY_ROOT_KEY=""2UNKEY_API_ID=""
Start the project
1npm run start
http://localhost:3000/public
to access the public route.http://localhost:3000/protected
with an Authorization
header containing your API key.Example public request using curl:
1curl http://127.0.0.1:3000/public
Example protected request using curl ( MAKE SURE THE API KEY has the access-unkeyed-route permission)
1curl -H "Authorization: Bearer <api_key>" http://localhost:3000/protected
2500 verifications and 100K successful rate‑limited requests per month. No CC required.