Skip to content

Fastify Spickzettel

Hochperformantes Node.js-Web-Framework mit geringem Overhead.

01

Einstieg

Hello Server

Fastify serialisiert JSON-Antworten automatisch.

fastify
import Fastify from "fastify";
const fastify = Fastify();

fastify.get("/", async () => {
  return { hello: "world" };
});

fastify.listen({ port: 3000 });

Schema-Validierung

JSON Schema für schnelle Validierung.

fastify
fastify.post("/user", {
  schema: {
    body: {
      type: "object",
      required: ["name"],
      properties: {
        name: { type: "string" }
      }
    }
  }
}, async (req) => req.body);

Plugins

Gekapselte Plugins mit Präfixen.

fastify
fastify.register(async (instance) => {
  instance.get("/plugin", async () => "ok");
}, { prefix: "/api" });

Was this helpful?