Serve JSON
Return objects to serve JSON responses. Primate automatically serializes returned objects to JSON.
Objects are JSON-serialized; use
response.json()
for granular control.
TypeScriptroutes/api.ts
import route from "primate/route";
route.get(() => ({ message: "Hello", data: [1, 2, 3] }));
TypeScriptroutes/index.ts
import response from "primate/response";
import route from "primate/route";
route.get(() => response.json({ error: "Not found" }, { status: 404 }));