Basic API using the Hono framework with Deno
This guide explains how to set up a basic API using the Hono framework with Deno runtime, protected by the Unkey API. You'll be guided through the following steps:
To install Deno, follow the instructions for your operating system:
Windows: Open PowerShell and run:
1irm https://deno.land/install.ps1 | iex
MacOS / Linux: Open a terminal and run:
1curl -fsSL https://deno.land/install.sh | sh
For more detailed installation instructions, visit Deno's official documentation.
Before running your application, you need to set up Unkey to manage API keys.
create_key
, read_key
, encrypt_key
, and decrypt_key
.1git clone https://github.com/Yash-1511/hono-unkey-deno.git
Since Deno has native support for npm packages, no manual installation is needed. You'll use npm:@unkey/api
directly in your code.
.env
Create a .env
file in your project directory to store environment variables. Add the following variables:
1UNKEY_ROOT_KEY=<Your_Root_Key>2UNKEY_API_ID=<Your_API_ID>
Replace <Your_Root_Key>
and <Your_API_ID>
with the respective values from the Unkey dashboard.
Now that everything is set up, you can start your server. Run the following command to start your app:
1deno task start
The server will start on port 8000.
Public Route: Access the root route (http://localhost:8000/) to get a public response:
1Hello Hono!
Protected Route: Access the protected route (http://localhost:8000/protected) by passing a valid API key in the Authorization
header:
1curl -H "Authorization: Bearer <Your_API_Key>" http://localhost:8000/protected
If the API key is valid, you will see the following response:
1{2 "message": "This is a protected route"3}
If the API key is missing or invalid, you will receive a 401 or 403 error.
You have successfully created an API using the Hono framework in Deno, secured by Unkey API authentication. Your API is protected by middleware that verifies API keys using Unkey, ensuring only authorized users can access protected routes.
For more information on Deno, Hono and Unkey, visit their official documentation:
2500 verifications and 100K successful rate‑limited requests per month. No CC required.