### Install dependencies and setup TypeScript using shell Source: https://hono.dev/llms-full.txt Run these commands to install the project's dependencies and initialize a TypeScript configuration file. ```sh npm i npx tsc --init ``` ```sh yarn yarn tsc --init ``` ```sh pnpm i pnpm exec tsc --init ``` ```sh bun i ``` -------------------------------- ### Install Project Dependencies Source: https://hono.dev/llms-full.txt Navigates into the project directory and installs the necessary node modules. ```sh cd my-app npm i ``` -------------------------------- ### Start the development server Source: https://hono.dev/docs/getting-started/nodejs Execute the dev script to start the local server, typically accessible at localhost:3000. ```sh npm run dev ``` ```sh yarn dev ``` ```sh pnpm dev ``` -------------------------------- ### Start Development Server Source: https://hono.dev/llms-full.txt Commands to launch the development server. ```npm npm run dev ``` ```yarn yarn dev ``` ```pnpm pnpm run dev ``` ```bun bun run dev ``` -------------------------------- ### Start the Bun development server Source: https://hono.dev/llms-full.txt Execute the dev script to start the application with hot reloading enabled. ```sh bun run dev ``` -------------------------------- ### Install project dependencies Source: https://hono.dev/docs/getting-started/nodejs Navigate to the project directory and install required packages using your preferred package manager. ```sh cd my-app npm i ``` ```sh cd my-app yarn ``` ```sh cd my-app pnpm i ``` ```sh cd my-app bun i ``` -------------------------------- ### Install dependencies Source: https://hono.dev/docs/getting-started/service-worker Install Hono and Vite using your preferred package manager. ```sh npm i hono npm i -D vite ``` ```sh yarn add hono yarn add -D vite ``` ```sh pnpm add hono pnpm add -D vite ``` ```sh bun add hono bun add -D vite ``` -------------------------------- ### Run development server Source: https://hono.dev/docs/getting-started/cloudflare-workers-vite Start the local development server using your preferred package manager. ```sh npm run dev ``` ```sh yarn dev ``` ```sh pnpm dev ``` ```sh bun run dev ``` -------------------------------- ### Create a basic Hono application Source: https://hono.dev/docs Initialize a Hono instance and define a simple GET route returning text. This example uses the default export pattern common in Cloudflare Workers. ```typescript import { Hono } from 'hono' const app = new Hono() app.get('/', (c) => c.text('Hono!')) export default app ``` -------------------------------- ### Run development server with Netlify CLI Source: https://hono.dev/llms-full.txt Start a local server to test your Edge Functions. ```sh netlify dev ``` -------------------------------- ### Select a platform template Source: https://hono.dev/llms-full.txt Choose the target runtime environment from the interactive CLI menu during project setup. ```text ? Which template do you want to use? aws-lambda bun cloudflare-pages ❯ cloudflare-workers deno fastly nextjs nodejs vercel ``` -------------------------------- ### Install Valibot Source: https://hono.dev/docs/guides/validation Install the Valibot validation library using your preferred package manager. ```sh npm i valibot ``` ```sh yarn add valibot ``` ```sh pnpm add valibot ``` ```sh bun add valibot ``` -------------------------------- ### Install ArkType Source: https://hono.dev/docs/guides/validation Install the ArkType validation library using your preferred package manager. ```sh npm i arktype ``` ```sh yarn add arktype ``` ```sh pnpm add arktype ``` ```sh bun add arktype ``` -------------------------------- ### Example directory structure for static files Source: https://hono.dev/docs/getting-started/nodejs A typical project layout for serving static assets. ```sh ./ ├── favicon.ico ├── index.ts └── static ├── hello.txt └── image.png ``` -------------------------------- ### Install gcloud CLI on macOS Source: https://hono.dev/llms-full.txt Uses Homebrew to install the Google Cloud SDK for managing resources from the command line. ```sh brew install --cask gcloud-cli ``` -------------------------------- ### Non-interactive project initialization Source: https://hono.dev/llms-full.txt Combine flags to specify the template and package manager while automatically installing dependencies. ```bash npm create hono@latest my-app -- --template vercel --pm npm --install ``` -------------------------------- ### Initialize a new Hono project with Bun Source: https://hono.dev/llms-full.txt Use the bun create command to scaffold a new project and install necessary dependencies. ```sh bun create hono@latest my-app ``` ```sh cd my-app bun install ``` -------------------------------- ### Run local development server Source: https://hono.dev/llms-full.txt Use the Vercel CLI to start a local development environment that mimics the Vercel platform. ```sh vercel dev ``` -------------------------------- ### Recommended directory structure for static files Source: https://hono.dev/llms-full.txt Example layout for organizing assets when using the serveStatic middleware. ```text ./ ├── favicon.ico ├── src └── static ├── demo │ └── index.html ├── fallback.txt ├── hello.txt └── images └── dinotocat.png ``` -------------------------------- ### Installing Standard Schema Validator Middleware Source: https://hono.dev/docs/guides/validation Install the middleware to support any validation library compatible with the Standard Schema specification. ```shell npm i @hono/standard-validator ``` ```shell yarn add @hono/standard-validator ``` ```shell pnpm add @hono/standard-validator ``` ```shell bun add @hono/standard-validator ``` -------------------------------- ### Create a Hello World Hono application Source: https://hono.dev/llms-full.txt Basic setup for a Hono application using a custom renderer and a catch-all route. ```tsx import { Hono } from 'hono' import { renderer } from './renderer' const app = new Hono() app.get('*', renderer) app.get('/', (c) => { return c.render(

Hello, Cloudflare Pages!

) }) export default app ``` -------------------------------- ### Run Local Development Server Source: https://hono.dev/llms-full.txt Starts the Hono application locally for testing and verification. ```sh npm run dev ``` -------------------------------- ### Recommended directory structure for static files Source: https://hono.dev/llms-full.txt Example layout for organizing assets when using serveStatic middleware. ```text ./ ├── favicon.ico ├── index.ts └── static ├── demo │ └── index.html ├── fallback.txt ├── hello.txt └── images └── dinotocat.png ``` -------------------------------- ### Basic SSG Plugin Examples Source: https://hono.dev/docs/helpers/ssg Practical examples of plugins that filter requests by method, filter responses by status code, or log generated file paths. ```typescript const getOnlyPlugin: SSGPlugin = { beforeRequestHook: (req) => { if (req.method === 'GET') { return req } return false }, } ``` ```typescript const statusFilterPlugin: SSGPlugin = { afterResponseHook: (res) => { if (res.status === 200 || res.status === 500) { return res } return false }, } ``` ```typescript const logFilesPlugin: SSGPlugin = { afterGenerateHook: (result) => { if (result.files) { result.files.forEach((file) => console.log(file)) } }, } ``` -------------------------------- ### Route Log Output Format Source: https://hono.dev/llms-full.txt Example of the console output generated when showRoutes is executed. ```text GET /v1/posts GET /v1/posts/:id POST /v1/posts ``` -------------------------------- ### Install Hono and Azure Functions Adapter Source: https://hono.dev/llms-full.txt Add the Hono framework and the specific Azure Functions adapter to your project. ```sh npm i @marplex/hono-azurefunc-adapter hono ``` ```sh yarn add @marplex/hono-azurefunc-adapter hono ``` ```sh pnpm add @marplex/hono-azurefunc-adapter hono ``` ```sh bun add @marplex/hono-azurefunc-adapter hono ``` -------------------------------- ### KV namespace creation output Source: https://hono.dev/llms-full.txt Example output from the wrangler command containing the binding name and preview ID. ```text { binding = "MY_KV", preview_id = "abcdef" } ``` -------------------------------- ### Hono Instance Methods Source: https://hono.dev/docs/api/hono Overview of the core methods available on a Hono instance for routing and application setup. ```APIDOC ## Hono Instance Methods ### Description An instance of `Hono` provides methods for defining routes, registering middleware, and managing the application lifecycle. ### Methods - **app.HTTP_METHOD([path,] handler|middleware...)** - Defines a route for a specific HTTP method. - **app.all([path,] handler|middleware...)** - Defines a route for all HTTP methods. - **app.on(method|method[], path|path[], handler|middleware...)** - Defines routes for specific methods and paths. - **app.use([path,] middleware)** - Registers middleware. - **app.route(path, [app])** - Mounts another Hono instance or sub-router. - **app.basePath(path)** - Sets a base path for the application. - **app.mount(path, anotherApp)** - Mounts another application. - **app.fetch(request, env, event)** - The fetch handler for the application. - **app.request(path, options)** - A helper to perform requests against the app. ``` -------------------------------- ### Initialize a Hono project Source: https://hono.dev/llms-full.txt Use the official starter kit to bootstrap a new project using various package managers or runtimes. ```sh npm create hono@latest ``` ```sh yarn create hono ``` ```sh pnpm create hono@latest ``` ```sh bun create hono@latest ``` ```sh deno init --npm hono@latest ``` -------------------------------- ### Create a basic Hono application for Netlify Source: https://hono.dev/llms-full.txt Define a simple GET route and export the application using the Netlify handle. ```ts import { Hono } from 'jsr:@hono/hono' import { handle } from 'jsr:@hono/hono/netlify' const app = new Hono() app.get('/', (c) => { return c.text('Hello Hono!') }) export default handle(app) ``` -------------------------------- ### Define Hono application routes for testing Source: https://hono.dev/llms-full.txt Set up basic GET and POST endpoints to be used in subsequent test examples. ```ts app.get('/posts', (c) => { return c.text('Many posts') }) app.post('/posts', (c) => { return c.json( { message: 'Created', }, 201, { 'X-Custom': 'Thank you', } ) }) ``` -------------------------------- ### Install Deno assertion library Source: https://hono.dev/llms-full.txt Use this command to add the standard assertion library from JSR to your Deno project. ```sh deno add jsr:@std/assert ``` -------------------------------- ### Create project directory Source: https://hono.dev/docs/getting-started/service-worker Initialize a new directory for the application and navigate into it. ```sh mkdir my-app cd my-app ``` -------------------------------- ### Basic Hello World application Source: https://hono.dev/llms-full.txt Use the fire function from @fastly/hono-fastly-compute to initialize the Hono application at the top level. ```ts // src/index.ts import { Hono } from 'hono' import { fire } from '@fastly/hono-fastly-compute' const app = new Hono() app.get('/', (c) => c.text('Hello Fastly!')) fire(app) ``` -------------------------------- ### Installing Zod Validator Middleware Source: https://hono.dev/docs/guides/validation Install the official Hono middleware for seamless Zod integration. ```shell npm i @hono/zod-validator ``` ```shell yarn add @hono/zod-validator ``` ```shell pnpm add @hono/zod-validator ``` ```shell bun add @hono/zod-validator ``` -------------------------------- ### Initialize Hono project for Alibaba Cloud FC3 Source: https://hono.dev/llms-full.txt Create the project directory and install dependencies including the Hono FC3 adapter and Serverless Devs CLI. ```npm mkdir my-app cd my-app npm i hono hono-alibaba-cloud-fc3-adapter npm i -D @serverless-devs/s esbuild mkdir src touch src/index.ts ``` ```yarn mkdir my-app cd my-app yarn add hono hono-alibaba-cloud-fc3-adapter yarn add -D @serverless-devs/s esbuild mkdir src touch src/index.ts ``` ```pnpm mkdir my-app cd my-app pnpm add hono hono-alibaba-cloud-fc3-adapter pnpm add -D @serverless-devs/s esbuild mkdir src touch src/index.ts ``` ```bun mkdir my-app cd my-app bun add hono hono-alibaba-cloud-fc3-adapter bun add -D esbuild @serverless-devs/s mkdir src touch src/index.ts ``` -------------------------------- ### Get HTTP Request Method in Hono Source: https://hono.dev/llms-full.txt Retrieves the HTTP method name (e.g., GET, POST) of the request. ```typescript import { Hono } from 'hono' const app = new Hono() // ---cut--- app.get('/about/me', async (c) => { const method = c.req.method // `GET` // ... }) ``` -------------------------------- ### Initialize Supabase project Source: https://hono.dev/llms-full.txt Run this command to initialize a new Supabase project structure in your current local directory. ```bash supabase init ``` -------------------------------- ### Initialize Hono project for WebAssembly using shell Source: https://hono.dev/llms-full.txt Use these commands to create a new directory and install Hono with the necessary Bytecode Alliance WASI tools. ```sh mkdir my-app cd my-app npm init npm i hono npm i -D @bytecodealliance/jco @bytecodealliance/componentize-js @bytecodealliance/jco-std npm i -D rolldown ``` ```sh mkdir my-app cd my-app npm init yarn add hono yarn add -D @bytecodealliance/jco @bytecodealliance/componentize-js @bytecodealliance/jco-std yarn add -D rolldown ``` ```sh mkdir my-app cd my-app pnpm init --init-type module pnpm add hono pnpm add -D @bytecodealliance/jco @bytecodealliance/componentize-js @bytecodealliance/jco-std pnpm add -D rolldown ``` ```sh mkdir my-app cd my-app npm init bun add hono bun add -D @bytecodealliance/jco @bytecodealliance/componentize-js @bytecodealliance/jco-std ``` -------------------------------- ### Test HEAD and GET responses Source: https://hono.dev/docs/guides/best-practices Verify that HEAD requests return the same status and headers as GET requests but with a null body. ```typescript // Always test both GET and HEAD responses it('handles HEAD requests correctly', async () => { const getRes = await app.request('/api/users') const headRes = await app.request('/api/users', { method: 'HEAD' }) expect(headRes.status).toBe(getRes.status) expect(headRes.headers.get('X-Total-Count')).toBe( getRes.headers.get('X-Total-Count') ) expect(headRes.body).toBe(null) }) ``` -------------------------------- ### Route path JSON response example Source: https://hono.dev/llms-full.txt Example of the JSON output returned when accessing the routePath property for a dynamic route. ```json { "path": "/posts/:id" } ``` -------------------------------- ### Start Development Server Source: https://hono.dev/docs/getting-started/service-worker Execute the development script using your preferred package manager. Access the local URL in your browser to complete the Service Worker registration. ```shell npm run dev ``` ```shell yarn dev ``` ```shell pnpm run dev ``` ```shell bun run dev ``` -------------------------------- ### Initialize and run Hono on Deno Source: https://hono.dev/llms-full.txt Commands to create a new project using the Hono template, navigate to the directory, and start the development server. ```sh deno init --npm hono --template=deno my-app ``` ```sh cd my-app ``` ```sh deno task start ``` -------------------------------- ### Install Azure Functions Core Tools on macOS Source: https://hono.dev/llms-full.txt Use Homebrew to install the necessary CLI tools for Azure Functions development. ```sh brew tap azure/functions brew install azure-functions-core-tools@4 ``` -------------------------------- ### Test GET request using app.request in Vitest Source: https://hono.dev/llms-full.txt Use app.request to simulate a GET request and validate the response status and body. ```ts describe('Example', () => { test('GET /posts', async () => { const res = await app.request('/posts') expect(res.status).toBe(200) expect(await res.text()).toBe('Many posts') }) }) ``` -------------------------------- ### Handle HEAD requests using GET routes Source: https://hono.dev/docs/guides/best-practices Hono automatically handles HEAD requests by converting them to GET and stripping the body. ```typescript // GOOD: This GET route automatically handles HEAD requests app.get('/api/users', async (c) => { const users = await getUsers() c.header('X-Total-Count', users.length.toString()) return c.json(users) }) // HEAD /api/users will return: // - Same headers as GET (including X-Total-Count) // - Status 200 // - No body (null) ``` -------------------------------- ### Get request path Source: https://hono.dev/docs/api/request Retrieves the request pathname. ```typescript app.get('/about/me', async (c) => { const pathname = c.req.path // `/about/me` // ... }) ``` -------------------------------- ### Create a Hello World application Source: https://hono.dev/docs/getting-started/cloudflare-workers Define a basic route in src/index.ts. The application must be exported as the default export for Cloudflare Workers compatibility. ```ts import { Hono } from 'hono' const app = new Hono() app.get('/', (c) => c.text('Hello Cloudflare Workers!')) export default app ``` -------------------------------- ### Get request method Source: https://hono.dev/docs/api/request Retrieves the HTTP method name of the request. ```typescript app.get('/about/me', async (c) => { const method = c.req.method // `GET` // ... }) ``` -------------------------------- ### Get request URL Source: https://hono.dev/docs/api/request Retrieves the full request URL string. ```typescript app.get('/about/me', async (c) => { const url = c.req.url // `http://localhost:8787/about/me` // ... }) ``` -------------------------------- ### Create wrangler.toml file Source: https://hono.dev/llms-full.txt Initialize the configuration file for Cloudflare Bindings. ```sh touch wrangler.toml ``` -------------------------------- ### client.[route].$[method](args, init) Source: https://hono.dev/llms-full.txt Calls a specific route on the test client with optional arguments and request initialization. ```APIDOC ## client.[route].$[method](args, init) ### Description Executes a request against a specific route using the test client. ### Parameters #### Arguments - **args** (Object) - Optional - An object containing `query`, `queries`, `param`, `json`, or `form` data. #### Initialization - **init** (RequestInit) - Optional - An object to set headers, method, body, etc. ### Request Example ```ts const res = await client.search.$get( { query: { q: 'hono' }, }, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': `application/json`, }, } ) ``` ``` -------------------------------- ### Get validated data Source: https://hono.dev/docs/api/request Retrieves data validated by Hono middleware. ```typescript app.post('/posts', async (c) => { const { title, body } = c.req.valid('form') // ... }) ``` -------------------------------- ### Create a basic Hono application for Node.js Source: https://hono.dev/docs/getting-started/nodejs Import the serve function from @hono/node-server to run the Hono app instance. ```ts import { serve } from '@hono/node-server' import { Hono } from 'hono' const app = new Hono() app.get('/', (c) => c.text('Hello Node.js!')) serve(app) ``` -------------------------------- ### Get Request Pathname in Hono Source: https://hono.dev/llms-full.txt Retrieves the pathname of the current request from the context. ```typescript import { Hono } from 'hono' const app = new Hono() // ---cut--- app.get('/about/me', async (c) => { const pathname = c.req.path // `/about/me` // ... }) ``` -------------------------------- ### Example rendered HTML output Source: https://hono.dev/llms-full.txt The resulting HTML output from the render call. ```html

Hello!

``` -------------------------------- ### Standard Fetch API Server Example Source: https://hono.dev/docs/concepts/web-standard A basic server implementation using the standard fetch handler. This pattern is natively compatible with runtimes like Cloudflare Workers and Bun. ```typescript export default { async fetch() { return new Response('Hello World') }, } ``` -------------------------------- ### GET / Source: https://hono.dev/llms-full.txt Accessing an endpoint with language detection enabled via various transport mechanisms. ```APIDOC ## GET / ### Description Detect language via query string, cookie, header, or path segments. ### Method GET ### Endpoint / ### Parameters #### Path Parameters - **pathSegment** (string) - Optional - Language code in the URL path (e.g., `/ar/home`). #### Query Parameters - **lang** (string) - Optional - Language code passed in the query string (e.g., `?lang=ar`). #### Request Body - **Accept-Language** (string) - Optional - Standard HTTP header for language negotiation. - **Cookie** (string) - Optional - Cookie containing the language preference (e.g., `language=ja`). ### Request Example ```sh # Via query parameter curl http://localhost:8787/?lang=ar # Via cookie curl -H 'Cookie: language=ja' http://localhost:8787/ # Via header curl -H 'Accept-Language: ar,en;q=0.9' http://localhost:8787/ ``` ### Response #### Success Response (200) - **body** (string) - Returns a string containing the detected language. ``` -------------------------------- ### client.[route].[method](args, init) Source: https://hono.dev/docs/helpers/testing Executes a request against a specific application route using the test client. ```APIDOC ## client.[route].[method](args, init) ### Description Invokes a specific HTTP method on a defined route. The method is prefixed with a `$` (e.g., `.$get`, `.$post`). ### Parameters #### Arguments - **args** (Object) - Optional - An object containing route-specific data: `query`, `param`, `header`, or `json` (body). - **init** (RequestInit) - Optional - A standard RequestInit object or an object containing a `headers` property to configure the request. ### Request Example ```typescript const res = await client.search.$get( { query: { q: 'hono' }, }, { headers: { Authorization: 'Bearer token', 'Content-Type': 'application/json', }, } ) ``` ### Response #### Success Response - **Response** (Promise) - A standard Fetch API Response object containing status, headers, and body data. ``` -------------------------------- ### Test Hono application Source: https://hono.dev/docs/getting-started/cloudflare-workers Example of defining an application and testing its response using vitest. ```ts import { Hono } from 'hono' const app = new Hono() app.get('/', (c) => c.text('Please test me!')) ``` ```ts describe('Test the application', () => { it('Should return 200 response', async () => { const res = await app.request('http://localhost/') expect(res.status).toBe(200) }) }) ``` -------------------------------- ### Resulting WIT directory structure Source: https://hono.dev/llms-full.txt The expected file system layout after successfully fetching dependencies. ```text wit ├── component.wit └── deps ├── wasi-cli-0.2.6 │   └── package.wit ├── wasi-clocks-0.2.6 │   └── package.wit ├── wasi-http-0.2.6 │   └── package.wit ├── wasi-io-0.2.6 │   └── package.wit └── wasi-random-0.2.6 └── package.wit ``` -------------------------------- ### Installing Zod Source: https://hono.dev/docs/guides/validation Add the Zod validation library to your project using your preferred package manager. ```shell npm i zod ``` ```shell yarn add zod ``` ```shell pnpm add zod ``` ```shell bun add zod ``` -------------------------------- ### Initialize Hono project with AWS CDK Source: https://hono.dev/docs/getting-started/aws-lambda Commands to initialize a new CDK project and install Hono and esbuild dependencies. Choose the command set corresponding to your preferred package manager. ```sh mkdir my-app cd my-app cdk init app -l typescript npm i hono npm i -D esbuild mkdir lambda touch lambda/index.ts ``` ```sh mkdir my-app cd my-app cdk init app -l typescript yarn add hono yarn add -D esbuild mkdir lambda touch lambda/index.ts ``` ```sh mkdir my-app cd my-app cdk init app -l typescript pnpm add hono pnpm add -D esbuild mkdir lambda touch lambda/index.ts ``` ```sh mkdir my-app cd my-app cdk init app -l typescript bun add hono bun add -D esbuild mkdir lambda touch lambda/index.ts ``` -------------------------------- ### Basic Hello World application in Bun Source: https://hono.dev/llms-full.txt A minimal Hono application exported as the default object for Bun's fetch handler. ```ts import { Hono } from 'hono' const app = new Hono() app.get('/', (c) => c.text('Hello Bun!')) export default app ``` -------------------------------- ### Install Cloudflare worker types Source: https://hono.dev/docs/getting-started/cloudflare-workers Commands to add the required type definitions for Cloudflare Workers. ```sh npm i --save-dev @cloudflare/workers-types ``` ```sh yarn add -D @cloudflare/workers-types ``` ```sh pnpm add -D @cloudflare/workers-types ``` ```sh bun add --dev @cloudflare/workers-types ``` -------------------------------- ### Run Azure Functions Locally Source: https://hono.dev/llms-full.txt Start the local development server for testing your Azure Function. ```sh npm run start ``` ```sh yarn start ``` ```sh pnpm start ``` ```sh bun run start ``` -------------------------------- ### Configure entry point and minification in wrangler.jsonc Source: https://hono.dev/getting-started/cloudflare-workers Specify the main entry file and enable minification for the Cloudflare Worker deployment. ```jsonc "main": "src/index.ts", "minify": true ``` -------------------------------- ### Initialize project using offline cache Source: https://hono.dev/llms-full.txt Use the --offline flag to create a project from local templates without fetching from the network. ```bash pnpm create hono@latest my-app --template deno --offline ``` -------------------------------- ### GET /api/animal/:type? Source: https://hono.dev/llms-full.txt An endpoint that matches both a base path and a path with an optional type parameter. ```APIDOC ## GET /api/animal/:type? ### Description Matches requests for animals. The type parameter is optional, allowing the endpoint to respond to both `/api/animal` and `/api/animal/dog`. ### Method GET ### Endpoint /api/animal/:type? ### Parameters #### Path Parameters - **type** (string) - Optional - The type of animal to match. ``` -------------------------------- ### Minimal interactive project initialization Source: https://hono.dev/llms-full.txt Run the initializer without arguments to enter interactive mode for template and option selection. ```bash npm create hono@latest my-app ``` -------------------------------- ### Initialize Hono project for Node.js Source: https://hono.dev/docs/getting-started/nodejs Use the create-hono command to scaffold a new project with the nodejs template. ```sh npm create hono@latest my-app ``` ```sh yarn create hono my-app ``` ```sh pnpm create hono my-app ``` ```sh bun create hono@latest my-app ``` ```sh deno init --npm hono my-app ``` -------------------------------- ### Get Full Request URL in Hono Source: https://hono.dev/llms-full.txt Retrieves the full URL string of the incoming request. ```typescript import { Hono } from 'hono' const app = new Hono() // ---cut--- app.get('/about/me', async (c) => { const url = c.req.url // `http://localhost:8787/about/me` // ... }) ``` -------------------------------- ### Create a basic Hello World application Source: https://hono.dev/llms-full.txt Define a minimal Hono application with a single root route. This code is portable across different runtimes with minor changes to imports and exports. ```ts import { Hono } from 'hono' const app = new Hono() app.get('/', (c) => { return c.text('Hello Hono!') }) export default app ``` -------------------------------- ### GET /posts/:postId/:authorId Source: https://hono.dev/llms-full.txt Retrieves a specific post using both post and author identifiers. ```APIDOC ## GET /posts/:postId/:authorId ### Description Handles routes with multiple path parameters to identify a post and its author. ### Method GET ### Endpoint /posts/:postId/:authorId ### Parameters #### Path Parameters - **postId** (string) - Required - The unique identifier for the post. - **authorId** (string) - Required - The unique identifier for the author. #### Query Parameters - **page** (string) - Optional - Pagination parameter. ### Response #### Success Response (200) - **title** (string) - The title of the post. - **body** (string) - The content of the post. #### Response Example { "title": "Night", "body": "Time to sleep" } ``` -------------------------------- ### GET /posts Source: https://hono.dev/llms-full.txt Retrieves post information using query parameters, supporting cookie-based authentication. ```APIDOC ## GET /posts ### Description Retrieves post information using query parameters. ### Method GET ### Endpoint /posts ### Parameters #### Query Parameters - **id** (string) - Required - The unique identifier for the post ### Request Example GET /posts?id=123 ### Response #### Success Response (200) - **res** (Response) - Standard fetch Response object ``` -------------------------------- ### Initialize a new Hono project Source: https://hono.dev/docs Commands to scaffold a new Hono project using various package managers and runtimes. ```sh npm create hono@latest ``` ```sh yarn create hono ``` ```sh pnpm create hono@latest ``` ```sh bun create hono@latest ``` ```sh deno init --npm hono@latest ``` -------------------------------- ### Create a basic Hono application Source: https://hono.dev/llms-full.txt Initialize a Hono instance and define a simple GET route. This code is portable across all supported runtimes. ```ts import { Hono } from 'hono' const app = new Hono() app.get('/', (c) => c.text('Hono!')) export default app ``` -------------------------------- ### Setup Hono JSX Renderer Source: https://hono.dev/docs/guides/jsx Configure a global renderer for Hono to handle JSX content. ```tsx import { Hono } from 'hono' const app = new Hono() app.use('*', async (c, next) => { c.setRenderer((content) => { return c.html( {content} ) }) await next() }) app.get('/about', (c) => { return c.render( <> About Page about page content ) }) export default app ``` -------------------------------- ### Build project using various package managers Source: https://hono.dev/docs/getting-started/nodejs Standard build commands for npm, yarn, pnpm, and bun. ```sh npm run build ``` ```sh yarn run build ``` ```sh pnpm run build ``` ```sh bun run build ``` -------------------------------- ### Configure Vite for Cloudflare Workers Source: https://hono.dev/docs/getting-started/cloudflare-workers-vite Setup vite.config.ts using the @cloudflare/vite-plugin and vite-ssr-components for server-side rendering. ```ts import { cloudflare } from '@cloudflare/vite-plugin' import { defineConfig } from 'vite' import ssrPlugin from 'vite-ssr-components/plugin' export default defineConfig({ plugins: [cloudflare(), ssrPlugin()], }) ``` -------------------------------- ### Initialize Hono project for Lambda@Edge Source: https://hono.dev/llms-full.txt Create a new directory and initialize a CDK application with TypeScript and Hono. ```sh mkdir my-app cd my-app cdk init app -l typescript npm i hono mkdir lambda ``` ```sh mkdir my-app cd my-app cdk init app -l typescript yarn add hono mkdir lambda ``` ```sh mkdir my-app cd my-app cdk init app -l typescript pnpm add hono mkdir lambda ``` ```sh mkdir my-app cd my-app cdk init app -l typescript bun add hono mkdir lambda ``` -------------------------------- ### createFactory(options?) Source: https://hono.dev/docs/helpers/factory Initializes a factory instance with optional environment types and application initialization logic. ```APIDOC ## createFactory(options?) ### Description Creates a factory instance to manage Hono environment types and application initialization. This helps avoid redundant type definitions across middleware and app instances. ### Parameters #### Options - **initApp** (Function) - Optional - A function to initialize the app instance created by `createApp()`. Receives the `app` instance as an argument. - **defaultAppOptions** (HonoOptions) - Optional - Default options for the Hono application instance. ### Request Example ```ts import { createFactory } from 'hono/factory' type Env = { Variables: { myVar: string } } const factory = createFactory() ``` ``` -------------------------------- ### Import Factory Helper Source: https://hono.dev/docs/helpers/factory Import the Hono class and factory utilities to start creating typed components. ```typescript import { Hono } from 'hono' import { createFactory, createMiddleware } from 'hono/factory' ``` -------------------------------- ### Importing hono/css utilities Source: https://hono.dev/docs/helpers/css Import the necessary functions and components from the hono/css module to start using CSS-in-JS. ```typescript import { Hono } from 'hono' import { css, cx, keyframes, Style, createCssContext } from 'hono/css' ``` -------------------------------- ### Build and deploy the application Source: https://hono.dev/llms-full.txt Execute the build process to compile TypeScript and then deploy the function to Alibaba Cloud. ```sh npm run build # Compile the TypeScript code to JavaScript npm run deploy # Deploy the function to Alibaba Cloud Function Compute ``` -------------------------------- ### GET /posts/:id Source: https://hono.dev/llms-full.txt Retrieves a specific post by its ID with optional pagination via query parameters. ```APIDOC ## GET /posts/:id ### Description Retrieves a specific post by its ID. Supports an optional page query parameter which is coerced into a number. ### Method GET ### Endpoint /posts/:id ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier for the post. #### Query Parameters - **page** (number) - Optional - The page number for pagination. ### Request Example GET /posts/123?page=1 ### Response #### Success Response (200) - **title** (string) - The title of the post. - **body** (string) - The content of the post. #### Response Example { "title": "Night", "body": "Time to sleep" } ```