01
快速上手
Hello Server
Fastify 自动序列化 JSON 响应。
fastify
import Fastify from "fastify";
const fastify = Fastify();
fastify.get("/", async () => {
return { hello: "world" };
});
fastify.listen({ port: 3000 });Schema 校验
用 JSON Schema 实现高速校验。
fastify
fastify.post("/user", {
schema: {
body: {
type: "object",
required: ["name"],
properties: {
name: { type: "string" }
}
}
}
}, async (req) => req.body);插件
带前缀的封装式插件。
fastify
fastify.register(async (instance) => {
instance.get("/plugin", async () => "ok");
}, { prefix: "/api" });这篇内容对您有帮助吗?