HTTP Server: Hello world

An example of an HTTP server that serves a "Hello World" message.

Edit on GitHub

HTTP servers need a handler function. This function is called for every request that comes in. It must return a `Response`. The handler function can be asynchronous (it may return a `Promise`).

function handler(_req: Request): Response {
  return new Response("Hello, World!");
}

To start the server on the default port, call `Ende.serve` with the handler.

Ende.serve(handler);

Run this example locally using the Ende CLI:

ende run -N https://docs.ende.sh/examples/scripts/http_server.ts

Additional resources