Usage
import { Metal, y } from "@metal/core";
import { createServer } from "http";
const m = new Metal();
const server = createServer(m.handler);
server.listen(4000, () => console.log(`Listening on http://localhost:4000`));
m.add("POST", "/users", async (ctx) => {
// This is type safe, since if the validation fails it will respond with 400.
const { email, password } = await ctx.body({
email: y.string().email().trim().lowercase().required(),
password: y.string().min(8).required(),
});
// Save to the database
const user = await db.user.create({ email, password });
return {
status: 201,
body: {
user,
},
};
});