Skip to content

Fastify Aide-mémoire

Framework web Node.js haute performance avec une surcharge minimale.

01

Démarrage

Serveur Hello World

Fastify sérialise automatiquement les réponses JSON.

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

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

fastify.listen({ port: 3000 });

Validation de schéma

JSON Schema pour une validation rapide.

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

Plugins

Plugins encapsulés avec préfixes.

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

Was this helpful?