Getting Started

Build HTTP servers with web standard APIs like fetch, Request, and Response.

Quick Start (CLI)

Create a server entry:

server.ts
export default {
  fetch(req: Request) {
    return Response.json({ hello: "world!" });
  },
};

Then, run the server using your favorite runtime:

npx srvx
Read more in Using CLI.
You can also try examples in the online playground

Quick Start (API)

Instead of using the srvx CLI, you can directly import the serve method to define a self-listening server entry.

Create a server entry:

server.ts
import { serve } from "srvx";

const server = serve({
  fetch(request) {
    return Response.json({ hello: "world!" });
  },
});

Install srvx as a dependency:

npm i srvx

Then, run the server using your favorite runtime:

node server.mjs

Starter Examples

ExampleSourceTry
elysiaexamples/elysianpx giget gh:h3js/srvx/examples/elysia srvx-elysia
expressexamples/expressnpx giget gh:h3js/srvx/examples/express srvx-express
h3examples/h3npx giget gh:h3js/srvx/examples/h3 srvx-h3
hello-worldexamples/hello-worldnpx giget gh:h3js/srvx/examples/hello-world srvx-hello-world
honoexamples/hononpx giget gh:h3js/srvx/examples/hono srvx-hono
jsxexamples/jsxnpx giget gh:h3js/srvx/examples/jsx srvx-jsx
node-handlerexamples/node-handlernpx giget gh:h3js/srvx/examples/node-handler srvx-node-handler
service-workerexamples/service-workernpx giget gh:h3js/srvx/examples/service-worker srvx-service-worker
websocketexamples/websocketnpx giget gh:h3js/srvx/examples/websocket srvx-websocket