A fastify web framework
npm install mapplejsnpm run dev - Starts development server
npm start - Runs production server
const fastify = require("fastify");
const { serviceInit } = require("mapplejs");
const app = fastify();
class UserService {
path = "users";
constructor(app) {
this.app = app;
}
// GET /users
async find(req, res) {
return [];
}
// GET /users/:id
async get(id, req, res) {
return { id };
}
// POST /users
async create(data, req, res) {
return { data };
}
// PATCH /users/:id
async patch(id, data, req, res) {
return { id, data };
}
// DELETE /users/:id
async delete(id, req, res) {
return { id };
}
}
app.decorate("service", {});
app.register(function (app) {
serviceInit(app, new UserService(app));
});
app.listen({ port: 3000 }).then(() => {
console.log("server is running on http://localhost:3000");
});
``