REST API
Modules
xxx
Usage
Think of modules as containers for related API endpoints. They help organize your routes logically - perfect for keeping your sanity intact!
import { buildModule } from "@vitnode/core/api/lib/module";
import { CONFIG_PLUGIN } from "@/config";
export const categoriesModule = buildModule({
pluginId: CONFIG_PLUGIN.id,
name: "categories",
routes: [] // We'll populate this soon!
});Nested Modules
Want to create a module hierarchy? VitNode's got your back! Nested modules are perfect for complex APIs.
import { buildModule } from "@vitnode/core/api/lib/module";
import { CONFIG_PLUGIN } from "@/config";
import { postsModule } from "./posts/posts.module";
export const categoriesModule = buildModule({
pluginId: CONFIG_PLUGIN.id,
name: "categories",
routes: [],
modules: [postsModule]
});This creates a structure: /api/{plugin_id}/categories/posts/*
Connecting Modules to the API
import { buildApiPlugin } from "@vitnode/core/api/lib/plugin";
import { CONFIG_PLUGIN } from "@/config";
import { categoriesModule } from "./api/modules/categories/categories.module";
export const blogApiPlugin = () => {
return buildApiPlugin({
pluginId: CONFIG_PLUGIN.pluginId,
modules: [categoriesModule]
});
};