Bun HTTP Server Starter: AI-Generated Code Prompt Example
CODE PREVIEW
エディタを読み込み中…
P
Prompt
A complete Bun HTTP server example with routing, JSON API, file serving, and WebSocket support - all using Bun's built-in APIs. No frameworks needed.
Bun HTTPサーバーのクイックスタートへようこそ!この作例では、BunのビルトインHTTPサーバー、ルーティング、JSON API、静的ファイル配信、WebSocket対応を、外部フレームワークや依存関係なしで実現しています。
なぜBunなのか?
- 🚀 ミリ秒単位の爆速起動
- 📦 Node.js APIと互換性あり
- 🔧 バンドラー、テストランナー、パッケージマネージャを内蔵
- ⚡️ WebSocket、ファイルI/O、SQLiteをネイティブサポート
実行方法
- コードを
server.tsとして保存 public/フォルダを作り、その中にindex.htmlを配置- 実行:
bun run server.ts - ブラウザで http://localhost:3000 を開く
デモ機能
- ルーティング — メソッド+パスをハンドラーにマッピング
- JSON API — GET /api/hello と POST /api/data エンドポイント
- 静的ファイル配信 — public/ 内のファイルを自動配信
- WebSocket — ポート3001でリアルタイム双方向通信
- クリーンな設計 — ルーターオブジェクトパターンで保守性向上
マイクロサービス、プロトタイピング、エッジコンピューティングに最適です。
Prompt Overview
Bun HTTP Server Quick Start! This example demonstrates Bun's built-in HTTP server, routing, JSON API, static file serving, and WebSocket support — all without external frameworks or dependencies.
Why Bun?
- 🚀 Blazing fast startup in milliseconds
- 📦 Compatible with Node.js API
- 🔧 Built-in bundler, test runner, and package manager
- ⚡️ Native support for WebSocket, file I/O, and SQLite
How to Run
- Save the code as
server.ts - Create a
public/folder and placeindex.htmlinside - Run:
bun run server.ts - Open http://localhost:3000 in your browser
Demo Features
- Routing — Map method + path to handlers
- JSON API — GET /api/hello and POST /api/data endpoints
- Static File Serving — Automatically serve files from
public/ - WebSocket — Real-time bidirectional communication on port 3001
- Clean Design — Router object pattern for better maintainability
Ideal for microservices, prototyping, and edge computing.
Was this prompt helpful?
Comments
Comments appear after moderation
この記事が役に立ったら投げ銭で応援
Apple Pay / Google Pay / カード (Visa/Mastercard/JCB/Amex) / Link / Alipay / WeChat Pay 対応 · Stripeで安全に決済
開発者が選ぶ最強ツール集
運営者が毎日使っているツール・ガジェット 6選