### Hono CLI - Installation Source: https://context7.com/honojs/cli/llms.txt Instructions for installing the Hono CLI globally and verifying the installation. ```APIDOC ## Installation ```bash # Global installation npm install -g @hono/cli # Verify installation hono --version # View all available commands hono --help ``` ``` -------------------------------- ### Hono Middleware Usage Examples (CLI) Source: https://context7.com/honojs/cli/llms.txt Examples demonstrating the use of various built-in Hono middleware via the `hono serve --use` command. This includes authentication, security, performance, logging, content processing, static file serving, and helper functions. These examples show how to dynamically inject middleware for different functionalities. ```bash # Authentication middleware hono serve --use 'basicAuth({ username: "user", password: "pass" })' hono serve --use 'bearerAuth({ token: "secret-token" })' hono serve --use 'jwt({ secret: "your-secret-key" })' # Security middleware hono serve --use 'cors({ origin: "https://example.com" })' hono serve --use 'csrf()' hono serve --use 'secureHeaders()' # Performance middleware hono serve --use 'compress()' hono serve --use 'cache({ cacheName: "my-cache" })' hono serve --use 'etag()' # Logging and monitoring hono serve --use 'logger()' hono serve --use 'timing()' hono serve --use 'requestId()' # Content processing hono serve --use 'prettyJSON()' hono serve --use 'bodyLimit({ maxSize: 100 * 1024 })' # Static file serving (Node.js) hono serve --use "serveStatic({ root: './public' })" # Helper functions available hono serve --use 'timeout(5000)' hono serve --use 'poweredBy()' hono serve --use 'methodOverride()' ``` -------------------------------- ### Start Hono Development Server (`hono serve`) Source: https://context7.com/honojs/cli/llms.txt Start a development server for your Hono application with hot middleware injection. This command supports TypeScript/JSX files with automatic transpilation, route visualization, and dynamic middleware loading from command-line arguments. It can start a server with an empty default app or on a custom port, and display all registered routes. ```bash # Start server with empty default app (no entry file needed) hono serve # Output: Listening on http://localhost:7070 # Start server on custom port hono serve -p 3000 src/app.ts # Output: Listening on http://localhost:3000 # Show all registered routes hono serve --show-routes src/app.ts # Output: # GET / # POST /api/users # GET /api/users/:id ``` -------------------------------- ### Install Hono CLI Source: https://context7.com/honojs/cli/llms.txt Install the Hono CLI globally using npm. After installation, you can verify the installation by checking the version and view all available commands using the `--version` and `--help` flags respectively. ```bash # Global installation npm install -g @hono/cli # Verify installation hono --version # View all available commands hono --help ``` -------------------------------- ### AI Agent Workflows with Hono CLI Source: https://context7.com/honojs/cli/llms.txt Illustrates how Hono CLI facilitates AI agent workflows through machine-readable JSON output and command chaining. Examples include searching for documentation, setting up automated testing pipelines, discovering documentation for specific features, and performing batch request testing. ```bash # AI search-to-documentation workflow TOPIC="middleware authentication" hono search "$TOPIC" | jq -r '.results[0].path' | xargs hono docs # Automated testing pipeline hono request -P /health && echo "Health check passed" hono request -P /api/users -X GET | jq '.status' # Documentation discovery for specific features hono search jwt --limit 3 | jq -r '.results[] | "\(.title): \(.path)"' # Output: # JWT - Middleware: /docs/middleware/builtin/jwt # JWT Authentication: /docs/guides/authentication # JWT Helper: /docs/helpers/jwt # Batch request testing for path in /api/users /api/posts /api/comments; do echo "Testing $path" hono request -P "$path" | jq '{status, headers: .headers["content-type"]}' done ``` -------------------------------- ### Hono CLI Development Workflow Source: https://context7.com/honojs/cli/llms.txt This snippet outlines a typical development cycle for Hono applications using the Hono CLI. It covers searching for implementation guidance, reading documentation, implementing features, testing code without a server, starting a development server with middleware, and building an optimized production bundle. ```bash # 1. Search for implementation guidance hono search "basic auth" --pretty # 2. Read relevant documentation hono docs /docs/middleware/builtin/basic-auth # 3. Implement feature in src/app.ts # ... write code ... # 4. Test without server hono request -P /protected \ -H 'Authorization: Basic YWRtaW46c2VjcmV0' \ src/app.ts # 5. Start development server with middleware hono serve --use 'logger()' --show-routes src/app.ts # 6. Build optimized production bundle hono optimize --minify -o dist/app.js src/app.ts ``` -------------------------------- ### `hono optimize` Source: https://context7.com/honojs/cli/llms.txt This command is for generating production-ready bundled applications with advanced optimizations, though specific usage examples were not provided in the input text. ```APIDOC ## `hono optimize` - Optimize Application Generates production-ready bundled applications with advanced optimizations. (Detailed usage examples were not provided in the source text.) ### Usage ```bash # Example placeholder (actual usage may vary) hono optimize [options] ``` ``` -------------------------------- ### `hono serve` - Development Server Source: https://context7.com/honojs/cli/llms.txt Start a development server for your Hono application with hot middleware injection. Supports TypeScript/JSX files with automatic transpilation, route visualization, and dynamic middleware loading. ```APIDOC ## `hono serve` - Development Server Start a development server for your Hono application with hot middleware injection. Supports TypeScript/JSX files with automatic transpilation, route visualization, and dynamic middleware loading from command-line arguments. ### Usage ```bash # Start server with empty default app (no entry file needed) hono serve # Output: Listening on http://localhost:7070 # Start server on custom port hono serve -p 3000 src/app.ts # Output: Listening on http://localhost:3000 # Show all registered routes hono serve --show-routes src/app.ts # Output: # GET / # POST /api/users # GET /api/users/:id ``` ``` -------------------------------- ### `hono request` - Test Application Requests Source: https://context7.com/honojs/cli/llms.txt Send HTTP requests to your Hono application using the built-in `app.request()` method without needing to start a server. Supports watch mode for automatic re-execution on file changes. ```APIDOC ## `hono request` - Test Application Requests Send HTTP requests to your Hono application using the built-in `app.request()` method without starting a server. Supports TypeScript, JSX, and all HTTP methods with custom headers and body data. Includes watch mode for automatic re-execution on file changes. ### Usage ```bash # GET request to default app (src/index.ts, src/index.tsx, src/index.js, or src/index.jsx) hono request # Output: # { # "status": 200, # "body": "Hello Hono!", # "headers": { # "content-type": "text/plain; charset=UTF-8" # } # } # GET request to specific path hono request -P /api/users hono request --path /health # POST request with JSON data hono request -P /api/users -X POST -d '{"name":"Alice","email":"alice@example.com"}' # PUT request with custom headers hono request -P /api/users/123 \ -X PUT \ -d '{"name":"Bob"}' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer eyJhbGc...' # DELETE request hono request -P /api/users/123 -X DELETE # Test specific file hono request -P /api src/app.ts hono request -P / src/custom-app.tsx # Watch mode - automatically resend request on file changes hono request -P /api/users --watch hono request -P /api/users -w # Multiple headers hono request \ -P /api/protected \ -H 'Authorization: Bearer token123' \ -H 'User-Agent: MyTestClient/1.0' \ -H 'X-Custom-Header: value' # Testing with different methods and data hono request -P /api/login -X POST -d '{"username":"admin","password":"secret"}' hono request -P /api/data -X PATCH -d '{"status":"active"}' ``` ``` -------------------------------- ### Test Hono Application Requests (`hono request`) Source: https://context7.com/honojs/cli/llms.txt Send HTTP requests to your Hono application using the built-in `app.request()` method without starting a server. This command supports TypeScript, JSX, and all HTTP methods with custom headers and body data. It includes a watch mode for automatic re-execution on file changes and allows testing specific application files. ```bash # GET request to default app (src/index.ts, src/index.tsx, src/index.js, or src/index.jsx) hono request # Output: # { # "status": 200, # "body": "Hello Hono!", # "headers": { # "content-type": "text/plain; charset=UTF-8" # } # } # GET request to specific path hono request -P /api/users hono request --path /health # POST request with JSON data hono request -P /api/users -X POST -d '{"name":"Alice","email":"alice@example.com"}' # PUT request with custom headers hono request -P /api/users/123 \ -X PUT \ -d '{"name":"Bob"}' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer eyJhbGc...' # DELETE request hono request -P /api/users/123 -X DELETE # Test specific file hono request -P /api src/app.ts hono request -P / src/custom-app.tsx # Watch mode - automatically resend request on file changes hono request -P /api/users --watch hono request -P /api/users -w # Multiple headers hono request \ -P /api/protected \ -H 'Authorization: Bearer token123' \ -H 'User-Agent: MyTestClient/1.0' \ -H 'X-Custom-Header: value' # Testing with different methods and data hono request -P /api/login -X POST -d '{"username":"admin","password":"secret"}' hono request -P /api/data -X PATCH -d '{"status":"active"}' ``` -------------------------------- ### Serve Hono App with Middleware (CLI) Source: https://context7.com/honojs/cli/llms.txt The `hono serve` command allows running a Hono application with various middleware directly from the command line. Middleware can be specified using the `--use` flag, supporting inline configurations for common Hono middleware like CORS, logger, authentication, and static file serving. This enables quick testing and development without modifying the application code. ```bash hono serve --use 'cors()' src/app.ts hono serve --use 'logger()' --use 'cors()' src/app.ts hono serve --use 'basicAuth({ username: "admin", password: "secret123" })' src/app.ts hono serve --use "serveStatic({ root: './' })" src/app.ts hono serve \ --use 'logger()' \ --use 'cors({ origin: "*" })' \ --use 'basicAuth({ username: "dev", password: "dev123" })' \ --show-routes \ -p 8080 \ src/app.ts hono serve \ --use 'secureHeaders()' \ --use 'csrf()' \ --use 'bodyLimit({ maxSize: 50 * 1024 })' \ src/app.ts hono serve \ --use 'prettyJSON()' \ --use 'compress()' \ src/api.ts ``` -------------------------------- ### Display Hono Documentation (`hono docs`) Source: https://context7.com/honojs/cli/llms.txt View Hono documentation directly in the terminal. This command fetches content from the official Hono website repository. It supports displaying the main documentation summary, specific documentation pages by path, piping from search results, and reading documentation paths from standard input. ```bash # Display main documentation summary (llms.txt) hono docs # View specific documentation pages hono docs /docs/concepts/motivation hono docs /docs/api/context hono docs /docs/guides/middleware hono docs /examples/basic # Pipe from search results (works with jq) hono search "middleware" | jq -r '.results[0].path' | xargs hono docs # Read from stdin echo "/docs/api/context" | hono docs ``` -------------------------------- ### Hono CLI Command Structure (TypeScript) Source: https://context7.com/honojs/cli/llms.txt This code snippet illustrates the basic structure of a Hono CLI command using the `commander` library. It shows how to create a command instance, define its name, description, and version, and register subcommands with their own arguments and options. This pattern is used across the Hono CLI for argument parsing. ```typescript import { Command } from 'commander' // Create command instance const program = new Command() program .name('hono') .description('CLI for Hono') .version('0.1.6') // Register commands program .command('serve') .description('Start server') .argument('[entry]', 'entry file') .option('-p, --port ', 'port number') .action(async (entry, options) => { // Command implementation }) program.parse() ``` -------------------------------- ### CI/CD Integration for Hono CLI Source: https://context7.com/honojs/cli/llms.txt This bash script demonstrates how to integrate Hono CLI into continuous integration pipelines. It includes automated testing of API endpoints with different methods and data payloads, and building an optimized production bundle. The script provides feedback on test results and exits with an error if any test fails. ```bash #!/bin/bash # ci-test.sh # Test all API endpoints endpoints=( "/health:GET" "/api/users:GET" "/api/users:POST:{\"name\":\"test\"}" ) for endpoint in "${endpoints[@]}"; do IFS=':' read -r path method data <<< "$endpoint" if [ -n "$data" ]; then result=$(hono request -P "$path" -X "$method" -d "$data") else result=$(hono request -P "$path" -X "$method") fi status=$(echo "$result" | jq -r '.status') if [ "$status" -ge 200 ] && [ "$status" -lt 300 ]; then echo "✓ $method $path: $status" else echo "✗ $method $path: $status" exit 1 fi done # Build optimized bundle hono optimize --minify echo "✓ Production build complete" ``` -------------------------------- ### TypeScript/JSX Transpilation with esbuild Source: https://context7.com/honojs/cli/llms.txt This snippet demonstrates how to use esbuild's bundler API to transpile TypeScript and JSX code for Hono applications. It includes configuration for bundling, formatting, target environment, JSX handling, and external dependencies. The bundled code is then executed via a data URL. ```typescript import * as esbuild from 'esbuild' // Build configuration for Hono apps const result = await esbuild.build({ entryPoints: ['src/app.tsx'], bundle: true, format: 'esm', target: 'node20', jsx: 'automatic', jsxImportSource: 'hono/jsx', platform: 'node', external: ['@hono/node-server'] }) // Execute bundled code via data URL const code = result.outputFiles[0].text const dataUrl = `data:text/javascript;base64,${Buffer.from(code).toString('base64')}` const module = await import(dataUrl) const app = module.default ``` -------------------------------- ### Search Hono Documentation (`hono search`) Source: https://context7.com/honojs/cli/llms.txt Search Hono's documentation using fuzzy search powered by Algolia. This command returns JSON by default for easy integration with other tools, but can also provide pretty-formatted output for human reading. It supports multi-word queries, custom search limits, and can be combined with tools like `jq` for automation. ```bash # Basic search (JSON output) hono search middleware # Output: # { # "query": "middleware", # "total": 5, # "results": [ # { # "title": "Middleware", # "category": "", # "url": "https://hono.dev/docs/guides/middleware#middleware", # "path": "/docs/guides/middleware" # } # ] # } # Human-readable output hono search middleware --pretty # Output: # Found 5 results: # # 1. Middleware # Category: # URL: https://hono.dev/docs/guides/middleware#middleware # Command: hono docs /docs/guides/middleware # Search with custom limit (default: 5, max: 20) hono search "getting started" --limit 10 # Multi-word queries hono search "basic auth" hono search "jwt authentication" # Combine with jq for automation hono search cors | jq -r '.results[].path' # Output: /docs/middleware/builtin/cors ``` -------------------------------- ### Dynamic Module Loading Utility (TypeScript) Source: https://context7.com/honojs/cli/llms.txt The `buildAndImportApp` utility function is used internally by the Hono CLI to load and transpile Hono applications at runtime. It supports loading both TypeScript/JSX and plain JavaScript files, and allows specifying external dependencies. This function is crucial for executing user-defined application code within the CLI. ```typescript import { buildAndImportApp } from './utils/build.js' import type { Hono } from 'hono' // Load TypeScript/JSX application const app: Hono = await buildAndImportApp('/path/to/app.ts', { external: ['@hono/node-server'] }) // Load plain JavaScript application const jsApp = await buildAndImportApp('/path/to/app.js') // Execute requests against loaded app const response = await app.request(new Request('http://localhost/')) const body = await response.text() console.log(body) // Output: application response ``` -------------------------------- ### Optimize Hono App for Production (CLI) Source: https://context7.com/honojs/cli/llms.txt The `hono optimize` command generates an optimized production bundle for Hono applications. It automatically selects the most efficient router, removes unused APIs, and can minify the output. Users can specify the entry and output files, enable minification, and control which optimizations are applied. ```bash # Generate optimized bundle (default: dist/index.js) hono optimize # Specify entry and output file hono optimize -o dist/app.js src/app.ts # Generate minified production bundle hono optimize -o dist/server.js src/index.ts --minify # Optimize with different entry points hono optimize -o dist/api.js src/api.ts hono optimize -o dist/web.js src/web.tsx # Specify environment target hono optimize -t node24 hono optimize -t es2024 # Disable specific optimizations hono optimize --minify --no-request-body-api-removal hono optimize --minify --no-context-response-api-removal hono optimize --minify --no-hono-api-removal # Build for deployment with all optimizations hono optimize --minify ``` -------------------------------- ### `hono docs` - Display Documentation Source: https://context7.com/honojs/cli/llms.txt This command allows you to view Hono documentation directly in your terminal. It can display the main documentation summary or specific pages. ```APIDOC ## `hono docs` - Display Documentation View Hono documentation directly in the terminal without leaving your development environment. Fetches content from the official Hono website repository. ### Usage ```bash # Display main documentation summary (llms.txt) hono docs # View specific documentation pages hono docs /docs/concepts/motivation hono docs /docs/api/context hono docs /docs/guides/middleware hono docs /examples/basic # Pipe from search results (works with jq) hono search "middleware" | jq -r '.results[0].path' | xargs hono docs # Read from stdin echo "/docs/api/context" | hono docs ``` ``` -------------------------------- ### `hono search` - Search Documentation Source: https://context7.com/honojs/cli/llms.txt Search through Hono's documentation using a fuzzy search engine. Returns JSON by default for programmatic use or pretty-formatted output for human readability. ```APIDOC ## `hono search` - Search Documentation Search through Hono's documentation using fuzzy search powered by Algolia. Returns JSON by default for easy integration with other tools, or pretty-formatted output for human reading. ### Usage ```bash # Basic search (JSON output) hono search middleware # Output: # { # "query": "middleware", # "total": 5, # "results": [ # { # "title": "Middleware", # "category": "", # "url": "https://hono.dev/docs/guides/middleware#middleware", # "path": "/docs/guides/middleware" # } # ] # } # Human-readable output hono search middleware --pretty # Output: # Found 5 results: # # 1. Middleware # Category: # URL: https://hono.dev/docs/guides/middleware#middleware # Command: hono docs /docs/guides/middleware # Search with custom limit (default: 5, max: 20) hono search "getting started" --limit 10 # Multi-word queries hono search "basic auth" hono search "jwt authentication" # Combine with jq for automation hono search cors | jq -r '.results[].path' # Output: /docs/middleware/builtin/cors ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.