From 81876e2bdc8a139217a1b3c62c0966cbe5bc1c19 Mon Sep 17 00:00:00 2001 From: mahdi Date: Sat, 25 Jan 2025 22:34:33 +0330 Subject: [PATCH] docs: update docs --- docs/FAQ.md | 80 ------- docs/documents/guides/1.getting-started.md | 116 ---------- docs/documents/guides/2.configuration.md | 126 ----------- docs/documents/guides/3.routing.md | 243 --------------------- docs/documents/guides/4.middleware.md | 225 ------------------- docs/documents/overview.md | 62 ------ 6 files changed, 852 deletions(-) delete mode 100644 docs/documents/guides/1.getting-started.md delete mode 100644 docs/documents/guides/2.configuration.md delete mode 100644 docs/documents/guides/3.routing.md delete mode 100644 docs/documents/guides/4.middleware.md delete mode 100644 docs/documents/overview.md diff --git a/docs/FAQ.md b/docs/FAQ.md index f8ad4d1..e69de29 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -1,80 +0,0 @@ -# FAQ - -## What is Gland? - -Gland is a lightweight web server framework designed for Node.js. It provides a flexible and extensible way to build web applications with support for middleware, routing, and a modular approach to configuration. - -## How do I get started with Gland? - -To get started with Gland, you can follow these simple steps: - -1. Install Gland via npm: - - ```bash - npm install @medishn/gland - ``` - -2. Create a basic server: - - ```typescript - import path from 'path'; - import gland from '@medishn/gland'; - - const g = new gland(); - g.load(path.join(__dirname, '.confmodule')); - g.init(3000, () => { - console.log('Server running on port 3000'); - }); - ``` - -3. Define your routes and handlers in a configuration file (`.confmodule`): - - Create a `.confmodule` file with the following content: - - ``` - path=router - ``` - -4. Create Router:(/router/example.ts) - - ```typescript - import { Context, Get, Route } from '@medishn/gland'; - - @Route('/') - export class Test { - @Get() - test(ctx: Context) { - ctx.write('hello world'); - ctx.end(); - } - } - ``` - -## How does Gland handle logging? - -Gland uses the internal logger package, [@medishn/gland-logger](https://github.com/medishen/gland-logger), to handle logging. You can access the logger using the `logger` property: - -```typescript -import gland from '@medishn/gland'; - -const g = new gland(); -const logger = new g.logger(); -``` - -## What is Qiu? - -Qiu is an internal query runner for Gland that supports various SQL databases, including MySQL, MariaDB, and PostgreSQL. For more information, visit the [Qiu repository](https://github.com/medishen/gland-qiu). - -## Where can I find more information? - -- [Gland Repository](https://github.com/medishen/gland) -- [Gland Logger](https://github.com/medishen/gland-logger) -- [Qiu](https://github.com/medishen/gland-qiu) - -## How can I report issues or contribute? - -Please report issues and contribute to the Gland project via the [GitHub repository](https://github.com/medishen/gland). For contributions, see the `CONTRIBUTING.md` file for guidelines. - -## Contact - -For further inquiries, you can reach us at [bitsgenix@gmail.com](mailto:bitsgenix@gmail.com). diff --git a/docs/documents/guides/1.getting-started.md b/docs/documents/guides/1.getting-started.md deleted file mode 100644 index 7989867..0000000 --- a/docs/documents/guides/1.getting-started.md +++ /dev/null @@ -1,116 +0,0 @@ -# Getting Started with @medishn/gland - -Welcome to the getting started guide for `@medishn/gland`, a lightweight, modular web framework for building scalable, high-performance Node.js applications. This guide will walk you through the installation, setup, and usage of `gland`, including its built-in support for logging, database queries, and routing. - -## Prerequisites - -Before starting, ensure you have the following: - -- **Node.js** (version 14 or higher) -- **npm** or **yarn** for package management -- **SQL Database** (MySQL, PostgreSQL, or MariaDB) if using the database query functionality - -## Installation - -The `@medishn/gland` package includes built-in integrations for logging and SQL database queries. When you install `gland`, the necessary dependencies are automatically included. - -To install `gland`, run the following command in your project directory: - -```bash -npm install @medishn/gland -``` - -## Basic Application Setup - -The following is a step-by-step guide to setting up a basic application using `gland`. - -### Step 1: Create a Web Server - -Start by creating an entry file for your server, such as `app.ts`: - -```typescript -import gland from '@medishn/gland'; -import path from 'path'; - -const app = new gland(); - -// Load the configuration file that specifies routes, middlewares, and other settings -app.load(path.join(__dirname, '.confmodule')); - -// Initialize the server on port 3000 -app.init(3000, () => { - console.log('Server is running on port 3000'); -}); -``` - -### Step 2: Configure the Server - -You can configure routes and other settings using a configuration file (`.confmodule`). This file defines where your route files and other modules are located. For example, in your `.confmodule`, you can specify the path to the router: - -``` -path=router -``` - -### Step 3: Define Routes - -Create a route module in the `router` directory. For instance, `router/index.ts` could contain a simple route that responds with "Hello, world!": - -```typescript -import { Context, Get, Route } from '@medishn/gland'; - -@Route('/') -export class Test { - @Get() - test(ctx: Context) { - ctx.write('Hello, world!'); - ctx.end(); - } -} -``` - -### Step 4: Run the Server - -Now you can run your server using `ts-node` or transpile your TypeScript files and run the generated JavaScript: - -```bash -ts-node app.ts -``` - -Your web server will be running at `http://localhost:3000/`, and visiting this URL should return the message "Hello, world!". - -## Adding Middleware - -`gland` supports middleware, which allows you to intercept and process requests before they reach your route handlers. You can define global middleware that applies to all routes or route-specific middleware. - -### Example: Adding Global Middleware - -```typescript -import gland, { Context, NxtFunction } from '@medishn/gland'; - -const app = new gland(); - -// Define a simple logging middleware -app.use(async (ctx: Context, next: NxtFunction) => { - console.log(`${ctx.method} ${ctx.url}`); - await next(); -}); - -// Load routes and start the server -app.load(path.join(__dirname, '.confmodule')); -app.init(3000, () => { - console.log('Server is running on port 3000'); -}); -``` - -In this example, every incoming request will log the HTTP method and URL before reaching the route handler. - -## Conclusion - -This guide has provided an introduction to getting started with `@medishn/gland`. With its modular architecture, support for logging and database queries, and robust routing system, `gland` is a powerful framework for building web applications. - -Explore the [API Documentation](./api) for detailed information about the available classes, methods, and decorators. - -### Next Steps - -- Learn how to add your own [Custom Middleware](./4.middleware.md). -- Dive into the [Routing System](./3.routing.md) for advanced routing features. \ No newline at end of file diff --git a/docs/documents/guides/2.configuration.md b/docs/documents/guides/2.configuration.md deleted file mode 100644 index f877cce..0000000 --- a/docs/documents/guides/2.configuration.md +++ /dev/null @@ -1,126 +0,0 @@ -# Configuration Guide for @medishn/gland - -This guide provides a comprehensive overview of the `.confmodule` configuration file, which is used to customize the behavior of the `@medishn/gland` framework. The `.confmodule` allows you to define routing, caching, and file-watching settings that control how the framework operates. - -## Table of Contents - -- [Configuration Guide for @medishn/gland](#configuration-guide-for-medishngland) - - [Table of Contents](#table-of-contents) - - [Introduction](#introduction) - - [Basic Configuration](#basic-configuration) - - [Configuration Options](#configuration-options) - - [Path Configuration](#path-configuration) - - [Router Configuration](#router-configuration) - - [Cache](#cache) - - [Watch](#watch) - - [Example](#example) - - [Best Practices](#best-practices) - ---- - -## Introduction - -`@medishn/gland` supports flexible configuration through the `.confmodule` file, allowing you to define routing paths, module caching, and file-watching behavior. This file is loaded when the framework starts, providing an easy way to configure the application without hardcoding settings. - -Key use cases for the `.confmodule` file include: -- Defining where your route files are located. -- Specifying which files should be loaded as routes. -- Enabling or disabling module caching. -- Enabling file watching for automatic reloads when files change. - -## Basic Configuration - -The `.confmodule` file uses a simple key-value format to specify configuration options. Below is an example of a basic configuration file: - -```ini -path = path.join(__dirname, 'router'); -router { - [0]: 'index.ts'; - [1]: 'test.ts'; -} -cache = true; -watch = false; -``` - -## Configuration Options - -The following sections describe the available options in the `.confmodule` file in detail. - -### Path Configuration - -- **`path`**: Defines the base directory where the router files are located. - - Type: `String` - - Default: `'router'` - - The `path` option typically uses `path.join` to resolve the absolute path to the directory where your route modules are stored. - - **Example:** - ```ini - path = path.join(__dirname, 'router'); - ``` - -### Router Configuration - -- **`router`**: Specifies the list of route files to be loaded by the framework. - - Type: `Array` - - Default: `[]` - - The `router` section lists the files that should be used as route modules. Each file is referenced with a specific index (e.g., `[0]`, `[1]`). The files are loaded in the order they appear. - - **Example:** - ```ini - router { - [0]: 'index.ts'; - [1]: 'test.ts'; - } - ``` - -### Cache - -- **`cache`**: Controls whether the router modules should be cached to improve performance. - - Type: `Boolean` - - Default: `true` - - When `cache` is set to `true`, the route modules are loaded once and then reused from memory, reducing overhead. If set to `false`, the modules are reloaded every time they are needed. - - **Example:** - ```ini - cache = true; - ``` - -### Watch - -- **`watch`**: Enables or disables file watching. When enabled, the framework will automatically reload route modules if changes are detected in the files. - - Type: `Boolean` - - Default: `false` - - When `watch` is set to `true`, the framework watches the route files for changes. If any file is modified, it will be reloaded automatically. This is useful during development but may not be necessary in production. - - **Example:** - ```ini - watch = false; - ``` - -### Example - -Here is a full example of a `.confmodule` file with all options: - -```ini -path = path.join(__dirname, 'router'); -router { - [0]: 'index.ts'; - [1]: 'test.ts'; -} -cache = true; -watch = false; -``` - -## Best Practices - -- **Separate configuration files by environment**: Create multiple configuration files for different environments (e.g., `.confmodule.dev` for development, `.confmodule.prod` for production) and load them based on the current environment. - -- **Use `cache` in production**: Caching the modules improves performance by reducing the need to reload them on each request. This is particularly useful for production environments. - -- **Enable `watch` during development**: Automatically reloading route modules when files change can speed up the development process by reducing the need for manual restarts. - -- **Keep the configuration simple**: Only include essential options in your `.confmodule` file to maintain clarity and avoid complexity. diff --git a/docs/documents/guides/3.routing.md b/docs/documents/guides/3.routing.md deleted file mode 100644 index 0e73fb4..0000000 --- a/docs/documents/guides/3.routing.md +++ /dev/null @@ -1,243 +0,0 @@ -# Routing Guide for @medishn/gland - -This guide provides a complete and comprehensive overview of the routing system in `@medishn/gland`. In this framework, routing is defined using decorators for HTTP methods, middleware, and GraphQL operations, allowing for clean and maintainable code. This document will cover the various route decorators, the usage of middleware at different levels, and how to define routes and apply middleware effectively. - -## Table of Contents - -- [Routing Guide for @medishn/gland](#routing-guide-for-medishngland) - - [Table of Contents](#table-of-contents) - - [Introduction](#introduction) - - [Route Decorators](#route-decorators) - - [@Get](#get) - - [@Post](#post) - - [@Put](#put) - - [@Delete](#delete) - - [@Patch](#patch) - - [@Head](#head) - - [@Options](#options) - - [@All](#all) - - [@Route](#route) - - [Middleware Decorators](#middleware-decorators) - - [@mid](#mid) - - [@mids](#mids) - - [Gmid](#gmid) - - [Best Practices](#best-practices) - ---- - -## Introduction - -In `gland`, routing is implemented using decorators, which are annotations placed above class methods or classes to define routes, middleware, and other HTTP-related behaviors. These decorators simplify the process of defining routes and enhance the readability of your code. - -Routes can be applied to methods using specific HTTP method decorators, such as `@Get`, `@Post`, `@Put`, and others. You can also apply middleware at different levels using `@mid`, `@mids`, and `Gmid` decorators, depending on the scope of the middleware. - -The routing system supports both RESTful operations and GraphQL requests, making it highly flexible for different API needs. - ---- - -## Route Decorators - -The following are the supported route decorators in `gland`, each corresponding to an HTTP method or route handler. These decorators are applied to class methods and are responsible for defining the route paths and behaviors. - -### @Get - -The `@Get` decorator is used to define a route that responds to HTTP `GET` requests. It is typically used for retrieving data or performing read-only operations. - -```typescript -@Get("/users") -public getUsers(ctx: Context) { - ctx.write({ users: [...] }); - ctx.end() -} -``` - -### @Post - -The `@Post` decorator defines a route that handles HTTP `POST` requests, commonly used to create new resources. - -```typescript -@Post("/users") -public createUser(ctx: Context) { - const userData = ctx.body; - ctx.write({ message: "User created successfully." }); - ctx.end() -} -``` - -### @Put - -The `@Put` decorator is for HTTP `PUT` requests, typically used for updating an existing resource. This method generally replaces the entire resource with the new data. - -```typescript -@Put("/users/:id") -public updateUser(ctx: Context) { - const { id } = ctx.params; - const updatedData = ctx.body; - // Update user with given ID - ctx.write({ message: `User ${id} updated successfully.` }); - ctx.end() -} -``` - -### @Delete - -The `@Delete` decorator is used for HTTP `DELETE` requests, usually to remove a resource. - -```typescript -@Delete("/users/:id") -public deleteUser(ctx: Context) { - const { id } = ctx.params; - // Delete the user with given ID - ctx.write({ message: `User ${id} deleted successfully.` }); - ctx.end() -} -``` - -### @Patch - -The `@Patch` decorator handles HTTP `PATCH` requests, used to partially update a resource. - -```typescript -@Patch("/users/:id") -public partiallyUpdateUser(ctx: Context) { - const { id } = ctx.params; - const updateFields = ctx.body; - // Partially update user with given ID - ctx.write({ message: `User ${id} updated successfully.` }); - ctx.end() -} -``` - -### @Head - -The `@Head` decorator is used for HTTP `HEAD` requests, similar to `GET` but without the response body. It is typically used for checking resource metadata. - -```typescript -@Head("/users") -public headUsers(ctx: Context) { - ctx.headers.set("Content-Length", "1024"); - ctx.end() -} -``` - -### @Options - -The `@Options` decorator handles HTTP `OPTIONS` requests, often used for preflight checks in cross-origin resource sharing (CORS). - -```typescript -@Options("/users") -public optionsUsers(ctx: Context) { - ctx.headers.set("Allow", "GET, POST, OPTIONS"); -} -``` - -### @All - -The `@All` decorator defines a route that responds to all HTTP methods (e.g., `GET`, `POST`, `PUT`, `DELETE`). - -```typescript -@All("/ping") -public handleAllRequests(ctx: Context) { - ctx.write({ message: "Pong!" }); - ctx.end() -} -``` - -### @Route - -The `@Route` decorator defines a base route for the entire class. It is used to prefix all methods within the class with a specific route path. - -```typescript -@Route("/users") -class UserController { - @Get("/") - public getUsers(ctx: Context) { - ctx.write({ users: [...] }); - ctx.end() - } - - @Post("/") - public createUser(ctx: Context) { - const userData = ctx.body; - ctx.write({ message: "User created." }); - ctx.end() - } -} -``` - -In this example, both methods would be available at `/users` , respectively. - ---- - -## Middleware Decorators - -Middleware in `gland` is used to process requests before they reach the route handler. Middleware can be applied at three levels: method-level (`@mid`), class-level (`@mids`), and file-level (`Gmid`). - -### @mid - -The `@mid` decorator is applied to individual methods to execute middleware before the route handler is invoked. Middleware functions passed to `@mid` receive the `Context` object and a `next` function, which is called to continue the request cycle. - -```typescript -@mid(authenticate) -@Get("/profile") -public getProfile(ctx: Context) { - ctx.write({ profile: {...} }); - ctx.end() -} -``` - -In this case, the `authenticate` middleware will be executed before the `getProfile` method. - -### @mids - -The `@mids` decorator is applied to an entire class and runs middleware before any methods in the class are executed. - -```typescript -@mids(logRequest) -@Route("/users") -class UserController { - @Get("/") - public getUsers(ctx: Context) { - ctx.write({ users: [...] }); - ctx.end() - } - - @Post("/") - public createUser(ctx: Context) { - const userData = ctx.body; - ctx.write({ message: "User created." }); - ctx.end() - } -} -``` - -In this example, `logRequest` middleware will run before any of the methods in the `UserController` class. - -### Gmid - -The `Gmid` decorator is applied at the file level and executes middleware for every route defined in that file. It ensures that the middleware applies to all classes and methods in the file. - -```typescript -// example.ts - -Gmid(globalAuth); - -@mids(localLog) -@Route('/test') -class TestController { - @Get() - public testMethod(ctx: Context) { - ctx.write({ message: 'Test method.' }); - ctx.end() - } -} -``` - -Here, `globalAuth` will be applied to every route in the `example.ts` file, while `localLog` will only apply to the `TestController` class. - -## Best Practices - -- **Use `@Route` for base paths**: Apply `@Route` to classes to organize and structure your routes logically. -- **Apply middleware at appropriate levels**: Use `@mid` for method-specific middleware, `@mids` for class-level middleware, and `Gmid` for file-level middleware to maintain clean and efficient code. -- **Avoid deep nesting**: Keep middleware simple and avoid deep nesting to maintain readability. -- **Use `@All` wisely**: Reserve `@All` for endpoints that need to handle diff --git a/docs/documents/guides/4.middleware.md b/docs/documents/guides/4.middleware.md deleted file mode 100644 index 41922ac..0000000 --- a/docs/documents/guides/4.middleware.md +++ /dev/null @@ -1,225 +0,0 @@ -# Middleware in @medishn/gland - -This document provides a detailed overview of middleware functionality within the `@medishn/gland` framework. Middleware in `gland` allows you to process requests, handle authentication, perform logging, and more, before they reach the route handlers. This guide will cover how to define and apply middleware using the available decorators and best practices for managing middleware in your application. - -## Table of Contents - -- [Middleware in @medishn/gland](#middleware-in-medishngland) - - [Table of Contents](#table-of-contents) - - [Introduction to Middleware](#introduction-to-middleware) - - [Middleware Decorators](#middleware-decorators) - - [@mid](#mid) - - [@mids](#mids) - - [Gmid](#gmid) - - [Defining Middleware Functions](#defining-middleware-functions) - - [Example Usage](#example-usage) - - [Best Practices](#best-practices) - ---- - -## Introduction to Middleware - -In `gland`, middleware functions are used to intercept and process HTTP requests before they reach the route handlers. Middleware can be used for various purposes, such as: - -- **Authentication and Authorization**: Verify user identity and permissions. -- **Logging**: Record request details for debugging and monitoring. -- **Request Transformation**: Modify request data or headers. -- **Error Handling**: Capture and handle errors gracefully. - -Middleware can be applied at different levels: method-level, class-level, and file-level, depending on the scope of its application. - ---- - -## Middleware Decorators - -`gland` provides several decorators for applying middleware at different levels of granularity: - -### @mid - -The `@mid` decorator is used to apply middleware to individual methods within a class. This decorator is useful when you need specific middleware to run only for certain route handlers. - -**Syntax:** - -```typescript -@mid(middlewareFunction) -``` - -**Example:** - -```typescript -import { Context, Get, mid } from '@medishn/gland'; - -const logRequest: MiddlewareFunction = async (ctx: Context, next: NxtFunction) => { - console.log(`Request to ${ctx.request.url}`); - await next(); -}; - -class UserController { - @mid(logRequest) - @Get("/profile") - public getProfile(ctx: Context) { - ctx.response.json({ profile: {...} }); - } -} -``` - -In this example, `logRequest` middleware is applied to the `getProfile` method only. - -### @mids - -The `@mids` decorator is applied at the class level, meaning that the specified middleware will be executed for all methods within the class. This is ideal for middleware that should apply to multiple routes or operations within the class. - -**Syntax:** - -```typescript -@mids(middlewareFunction) -``` - -**Example:** - -```typescript -import { Context, Get, mids, Route } from '@medishn/gland'; - -const authenticate: MiddlewareFunction = async (ctx: Context, next: NxtFunction) => { - if (!ctx.request.headers['authorization']) { - ctx.response.status(401).json({ error: 'Unauthorized' }); - return; - } - await next(); -}; - -@mids(authenticate) -@Route("/users") -class UserController { - @Get("/") - public getUsers(ctx: Context) { - ctx.response.json({ users: [...] }); - } - - @Post("/") - public createUser(ctx: Context) { - const userData = ctx.request.body; - ctx.response.json({ message: "User created." }); - } -} -``` - -In this example, `authenticate` middleware is applied to all methods in the `UserController` class. - -### Gmid - -The `Gmid` decorator is used at the file level to apply middleware to all routes defined within that file. This is useful for applying global middleware that should be executed for every route in a file. - -**Syntax:** - -```typescript -Gmid(middlewareFunction); -``` - -**Example:** - -```typescript -import { Context, Get, Gmid, Route } from '@medishn/gland'; - -const globalLogger: MiddlewareFunction = async (ctx: Context, next: NxtFunction) => { - console.log(`Global log: ${ctx.request.method} ${ctx.request.url}`); - await next(); -}; - -Gmid(globalLogger); - -@Route("/test") -class TestController { - @Get("/") - public testMethod(ctx: Context) { - ctx.response.json({ message: "Test route." }); - } -} -``` - -In this example, `globalLogger` middleware is applied to all routes in the file. - ---- - -## Defining Middleware Functions - -Middleware functions in `gland` should follow this signature: - -```typescript -type MiddlewareFunction = (ctx: Context, next: NxtFunction) => Promise; -``` - -- **ctx**: The `Context` object provides access to the request and response, and allows you to manipulate the request data or response. -- **next**: The `NxtFunction` is a function that must be called to pass control to the next middleware or route handler. - -**Example of a Middleware Function:** - -```typescript -const validateInput: MiddlewareFunction = async (ctx: Context, next: NxtFunction) => { - if (!ctx.request.body || !ctx.request.body.username) { - ctx.response.status(400).json({ error: 'Bad Request' }); - return; - } - await next(); -}; -``` - -This middleware function checks if the request body contains a `username` field and returns a 400 error if it does not. - ---- - -## Example Usage - -Here is a complete example showcasing how to use different levels of middleware in a `gland` application. - -```typescript -import gland, { Get, Post, mid, mids, Route, Gmid } from '@medishn/gland'; - -const logger: MiddlewareFunction = async (ctx: Context, next: NxtFunction) => { - console.log(`Received request: ${ctx.request.method} ${ctx.request.url}`); - await next(); -}; - -const authenticate: MiddlewareFunction = async (ctx: Context, next: NxtFunction) => { - if (!ctx.request.headers['authorization']) { - ctx.response.status(401).json({ error: 'Unauthorized' }); - return; - } - await next(); -}; - -Gmid(logger); - -@mids(authenticate) -@Route("/api") -class ApiController { - @Get("/data") - public getData(ctx: Context) { - ctx.response.json({ data: "Some data" }); - } - - @Post("/submit") - @mid(validateInput) - public submitData(ctx: Context) { - ctx.response.json({ message: "Data submitted successfully." }); - } -} - -const app = new gland(); -app.loadRoutes(ApiController); -app.init(3000, () => console.log("Server is running on port 3000")); -``` - -In this example: -- `logger` middleware is applied globally to all routes in the file. -- `authenticate` middleware is applied to all routes in the `ApiController` class. -- `validateInput` middleware is applied only to the `submitData` method. - ---- - -## Best Practices - -- **Scope Appropriately**: Apply middleware at the appropriate level (method, class, or file) based on its intended use to ensure clear and maintainable code. -- **Minimize Complexity**: Keep middleware functions simple and focused on a single task to improve readability and maintainability. -- **Order Matters**: Middleware is executed in the order it is applied. Ensure that middleware dependencies are handled correctly by placing them in the correct order. -- **Error Handling**: Implement error handling within middleware to manage unexpected issues and provide meaningful feedback to the client. \ No newline at end of file diff --git a/docs/documents/overview.md b/docs/documents/overview.md deleted file mode 100644 index bfe57c0..0000000 --- a/docs/documents/overview.md +++ /dev/null @@ -1,62 +0,0 @@ -# Overview of @medishn/gland - -`@medishn/gland` is a lightweight, modular web framework designed to streamline the development of Node.js applications. Built for developers who value performance, flexibility, and ease of use, `gland` offers a powerful foundation for building APIs, web services, and other web applications. - -## Key Features - -1. **Modular Architecture**: `gland` adopts a modular design, allowing developers to load and configure routes, middleware, and other components dynamically through a simple configuration file (`.confmodule`). - -2. **Routing with Decorators**: Define your routes using TypeScript decorators like `@Get()`, `@Post()`, `@Put()`, `@Delete()`, and `@Route()`. This makes your code cleaner and more declarative. - -3. **Middleware Support**: Add and manage middleware easily at both global and route levels. Middleware functions can intercept and manipulate requests and responses, providing flexibility in handling authentication, logging, and more. - -4. **Integrated Logger**: `gland` comes with an integrated logger from the `@medishn/gland-logger` package, allowing for seamless logging with customizable log levels. Whether logging to the console or implementing more advanced logging strategies, the logger provides robust support for tracking and debugging. - -5. **Performance-Focused**: Optimized for performance, `gland` can process a high volume of requests with minimal overhead. Recent benchmarks show exceptional performance with low average response times, even under heavy loads. - -## Use Cases - -- **API Development**: Perfect for building RESTful APIs or GraphQL backends with support for decorators and middleware. -- **Web Services**: Build microservices with ease, leveraging the modular architecture to scale your services independently. -- **Enterprise Applications**: With SQL database integration and robust logging, `gland` is well-suited for large-scale enterprise applications. - -## Example - -Here’s a simple example of how to use `gland` to create a basic web server: - -```typescript -import path from 'path'; -import gland from '@medishn/gland'; - -const app = new gland(); -app.load(path.join(__dirname, '.confmodule')); - -app.init(3000, () => { - console.log('Server is running on port 3000'); -}); -``` - -In the configuration file (`.confmodule`), define the path to your routes and other settings: - -```ini -path=router -``` - -And in your routing module: - -```typescript -import { Context, Get, Route } from '@medishn/gland'; - -@Route('/') -export class Test { - @Get() - test(ctx: Context) { - ctx.write('hello world'); - ctx.end(); - } -} -``` - -## Conclusion - -`@medishn/gland` is a versatile and efficient framework that helps developers build modern web applications with ease. Its modular design, performance optimizations, and built-in support for logging and database management make it an excellent choice for both small projects and large-scale enterprise applications. \ No newline at end of file