|
| 1 | +{ |
| 2 | + "id": 91, |
| 3 | + "slug": "built-in-http-server", |
| 4 | + "title": "Built-in HTTP server", |
| 5 | + "category": "tooling", |
| 6 | + "difficulty": "beginner", |
| 7 | + "jdkVersion": "18", |
| 8 | + "oldLabel": "Java 8", |
| 9 | + "modernLabel": "Java 18+", |
| 10 | + "oldApproach": "External Server / Framework", |
| 11 | + "modernApproach": "jwebserver CLI", |
| 12 | + "oldCode": "// Install and configure a web server\n// (Apache, Nginx, or embedded Jetty)\n\n// Or write boilerplate with com.sun.net.httpserver\nHttpServer server = HttpServer.create(\n new InetSocketAddress(8080), 0);\nserver.createContext(\"/\", exchange -> { ... });\nserver.start();", |
| 13 | + "modernCode": "// Terminal: serve current directory\n$ jwebserver\n\n// Or use the API (JDK 18+)\nvar server = SimpleFileServer.createFileServer(\n new InetSocketAddress(8080),\n Path.of(\".\"),\n OutputLevel.VERBOSE);\nserver.start();", |
| 14 | + "summary": "Java 18 includes a built-in minimal HTTP server for prototyping and file serving.", |
| 15 | + "explanation": "JDK 18 added a simple, zero-dependency HTTP file server accessible via the jwebserver command-line tool or the SimpleFileServer API. It serves static files from a given directory with no configuration needed. The CLI tool is ideal for quick prototyping, testing, and ad-hoc file sharing — no external dependencies or frameworks required. The API allows programmatic use with customizable handlers and output levels.", |
| 16 | + "whyModernWins": [ |
| 17 | + { "icon": "🚀", "title": "Zero setup", "desc": "Run jwebserver in any directory — no installation, config, or dependencies needed." }, |
| 18 | + { "icon": "📦", "title": "Built into the JDK", "desc": "Ships with every JDK 18+ installation, always available on any machine with Java." }, |
| 19 | + { "icon": "🧪", "title": "Great for prototyping", "desc": "Serve static files instantly for testing HTML, APIs, or front-end development." } |
| 20 | + ], |
| 21 | + "support": { |
| 22 | + "state": "available", |
| 23 | + "description": "Available since JDK 18 (March 2022)" |
| 24 | + }, |
| 25 | + "prev": "tooling/compact-object-headers", |
| 26 | + "next": "tooling/aot-class-preloading", |
| 27 | + "related": [ |
| 28 | + "io/http-client", |
| 29 | + "tooling/single-file-execution", |
| 30 | + "tooling/jshell-prototyping" |
| 31 | + ] |
| 32 | +} |
0 commit comments