Creates an instance of the Febby class.
The application configuration.
Protected
appProtected
mainProtected
redis
Static
Protected
instance
Private
connectPrivate
connectConfigures CRUD (Create, Read, Update, Delete) operations for a model and registers corresponding routes.
febby.crud("/api/users", {
crud: true,
middlewares: [],
get: [GetMiddleware],
post: [],
put: [PutMiddleware],
delete: [],
}, userModel);
Optional
path: string
= "/"
The base URL path for the CRUD operations.
The CRUD configuration.
The Mongoose model for the data.
Optional
router: Router = ...
The router to which the CRUD routes should be registered (default is the main router).
Registers a final middleware function to be used at the end of the middleware chain.
febby.finalHandler((req, res, next) => {
// Final middleware logic
next();
});
Load OpenAPI configuration from a YAML file and register routes based on the specification.
This method is used when you want to create your application using an OpenAPI specification in YAML format. It reads the YAML file, parses it, and generates routes and controllers based on the specification. include x-controller,x-middlewares in each route definition for mapping.
A Promise that resolves when the OpenAPI configuration is successfully loaded and routes are registered.
// Load OpenAPI configuration from a YAML file and register routes with default options.
await loadOpenAPIConfigYAML("/path/to/openapi.yaml");
// Load OpenAPI configuration from a YAML file and customize controller and middleware options.
const customOptions = {
controllers: {
UserController: (req, res) => { /* Custom UserController logic * / },
},
middleware: [
(req, res, next) => { /* Custom middleware logic * / },
],
openApiValidatorOptions: {
validateApiSpec: true,
validateResponses: true,
validateRequests: true,
}
};
await loadOpenAPIConfigYAML("/path/to/openapi.yaml", customOptions);
// Load OpenAPI configuration from a YAML file and provide controller and middleware options.
const customOptions = {
controllers: path.join(__dirname, 'controllers'), // path to controller directory
middleware: path.join(__dirname, 'middlewares'), // path to middleware directory
openApiValidatorOptions: {
validateApiSpec: true,
validateResponses: true,
validateRequests: true,
}
};
await loadOpenAPIConfigYAML("/path/to/openapi.yaml", customOptions);
The path to the OpenAPI YAML spec file.
An optional configuration object that holds controller, middleware definitions, and validation settings.
Registers a middleware function to be used in the application.
febby.middleware((req, res, next) => {
// Custom middleware logic
next();
});
The middleware function to be registered.
Optional
router: Router = ...
The router to which the middleware should be attached (default is the main router).
Registers an array of middleware functions to be used in the application.
febby.middlewares([
(req, res, next) => {
// Custom middleware 1 logic
next();
},
(req, res, next) => {
// Custom middleware 2 logic
next();
},
]);
Optional
router: Router = ...
The router to which the middlewares should be attached (default is the main router).
Defines a Mongoose model for data storage and retrieval.
const User = febby.model("User", userSchema);
The name of the Mongoose model.
Optional
schema: Schema<any, Model<any, any, any, any, any>, {}, {}, {}, {}, DefaultSchemaOptions, {}>
The schema for the Mongoose model.
Registers a route with a specified path, HTTP method, handler function, and optional middlewares.
febby.route({
method: "get",
path: "/api/users",
handler: (req, res) => {
// Handle GET request for /api/users
},
middlewares: [],
});
The route configuration.
Creates and returns a new router instance.
const apiRouter = febby.router("/api");
The base URL path for the new router.
Optional
router: Router
The parent router to which the new router should be attached (default is the main router).
Optional
options:
RouterOptions
Options for configuring the new router.
Registers multiple routes from an array of route configurations.
febby.routes([
{
method: "get",
path: "/api/users",
handler: (req, res) => {
// Handle GET request for /api/users
},
},
{
method: "post",
path: "/api/users",
handler: (req, res) => {
// Handle POST request for /api/users
},
},
]);
Generated using TypeDoc
The Febby class represents the main application framework. It initializes and configures the Express.js application and provides methods for routing, middleware, and database connections.