{"id":20371414,"url":"https://github.com/yldrmzffr/muzu","last_synced_at":"2025-04-12T06:24:58.276Z","repository":{"id":176384813,"uuid":"656386929","full_name":"yldrmzffr/muzu","owner":"yldrmzffr","description":"\"Muzu\" is a TypeScript npm library for server-side HTTP request handling and routing.","archived":false,"fork":false,"pushed_at":"2024-05-05T22:50:50.000Z","size":245,"stargazers_count":7,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T01:51:07.919Z","etag":null,"topics":["backend","basic","decorators","http","http-server","nodejs","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/muzu","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yldrmzffr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-20T21:12:32.000Z","updated_at":"2024-07-10T14:14:12.000Z","dependencies_parsed_at":"2024-05-05T23:30:41.590Z","dependency_job_id":"f0f34337-2a75-49f8-a0aa-6ff12719ddd9","html_url":"https://github.com/yldrmzffr/muzu","commit_stats":null,"previous_names":["yldrmzffr/muzu"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yldrmzffr%2Fmuzu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yldrmzffr%2Fmuzu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yldrmzffr%2Fmuzu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yldrmzffr%2Fmuzu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yldrmzffr","download_url":"https://codeload.github.com/yldrmzffr/muzu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248526428,"owners_count":21118898,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","basic","decorators","http","http-server","nodejs","typescript"],"created_at":"2024-11-15T01:07:51.808Z","updated_at":"2025-04-12T06:24:58.242Z","avatar_url":"https://github.com/yldrmzffr.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Muzu: TypeScript HTTP Request Handling and Routing Library\n\n**Muzu** is a powerful TypeScript npm library designed for server-side HTTP request handling and routing. It provides developers with a seamless and efficient way to handle and route HTTP requests in their Node.js applications.\n\n## Installation\n\nTo incorporate Muzu into your project, you can easily install it via npm using the following command:\n\n```shell\nnpm install muzu\n```\n\n## Usage\n\nHere is an in-depth example demonstrating how to leverage the capabilities of Muzu in your application:\n\n```typescript\nimport { MuzuServer, Request, Response } from 'muzu';\n\n// Create a new instance of the MuzuServer\nconst app = new MuzuServer();\nconst { Post, Controller } = app;\n\n@Controller('auth')\nclass TestController {\n\n  @Post('login')\n  login(req: Request, res: Response) {\n    const { username, password } = req.body;\n    \n    // Implement your login logic here\n\n    return {\n      status: true\n    };\n  }\n\n}\n\n// Start the server and listen on port 8080\napp.listen(8080);\n```\n\nIn this example, we instantiate a new `MuzuServer` and utilize the `@Post` and `@Controller` decorators to define a route for handling POST requests at the '/login' endpoint within the 'auth' base route.\n\nYou can also handle other HTTP methods by using decorators such as `@Get`, `@Put`, `@Delete`, and `@Patch` accordingly.\n\nInside the `login` method, you can implement the necessary logic to handle the incoming request. In this case, we return a simple object `{ status: true }` as the response.\n\nThe server is started and set to listen on port 8080 using the `listen` method of the `MuzuServer` instance.\n\n## Middleware\n\nMuzu supports middleware functions that can be applied to routes to execute specific logic before the route handler. Middleware functions can be used for tasks such as logging, authentication, and data validation.\n`@Middleware` decorator can be used to apply middleware functions to specific routes. Let's see an example:\n\n```typescript\nimport {MuzuServer, Request, Response} from 'muzu';\nimport {HttpException} from \"./http.exception\";\n\n// Create a new instance of the MuzuServer\nconst app = new MuzuServer();\nconst {Post, Controller, Middleware} = app;\n\n// Create a Middleware Function\nfunction LoggerMiddleware(req: Request) {\n  console.log(`Request Received: ${req.url}`);\n}\n\n// Create a Middleware Function\nfunction AuthMiddleware(req: Request) {\n  const {token} = req.headers;\n\n  if (!token) {\n    throw new HttpException('Unauthorized', 401);\n  }\n  \n  const user = getUserFromToken(token);\n  \n  // You can attact the custom data to the request object\n  req.user = user;\n}\n\n@Controller('auth')\nclass TestController {\n\n  @Post('login')\n  @Middleware(AuthMiddleware, LoggerMiddleware) // Apply Middleware to the 'login' route\n  login(req: Request, res: Response) {\n    const {user} = req; // Access the objects attached by the middleware\n\n    // Implement your login logic here\n\n    return {\n      status: true\n    };\n  }\n\n}\n\n// Start the server and listen on port 8080\napp.listen(8080);\n```\n\n## Exception Handling\n\nMuzu provides a comprehensive exception handling mechanism. You can create custom exception classes by extending the `HttpException` class and utilize them within your application. Let's see an example:\n\n```typescript\nimport { MuzuServer, Request, Response, HttpException } from 'muzu';\n\n// Custom Exception Class\nclass UserNotFoundException extends HttpException {\n  constructor(details?: string) {\n    super('User Not Found!', 404, details);\n  }\n}\n\nconst app = new MuzuServer();\nconst { Post, Controller } = app;\n\n@Controller('auth')\nclass TestController {\n\n  @Get('user')\n  getUser(req: Request, res: Response) {\n    const username = req.body.username;\n    \n    // Throw a UserNotFoundException\n    throw new UserNotFoundException({\n      username\n    });\n    \n    // The code below will not be executed because an exception is thrown.\n\n    return {\n      status: true\n    };\n  }\n\n}\n\napp.listen(8080);\n```\n\nIn this example, we create a custom exception class `UserNotFoundException` that extends the `HttpException` class. Inside the `getUser` method of the `TestController` class, we throw an instance of this custom exception class. The thrown exception will be automatically caught and handled by the `handleException` method of the `MuzuServer` instance.\n\n### Exception Response\n\nWhen an exception is thrown and caught, Muzu automatically generates an exception response with relevant details. Here is an example response for the `UserNotFoundException`:\n\n```json\n{\n  \"status\": 404,\n  \"message\": \"User Not Found!\",\n  \"details\": {\n    \"username\": \"muzu\"\n  }\n}\n```\n\n## Contributing\n\nWe welcome contributions from the community to enhance and improve Muzu. If you're interested in contributing, please visit our GitHub repository: [Muzu GitHub Repo](https://github.com/yldrmzffr/muzu)\n\n## License\n\nMuzu is released under the MIT License. For more information, please refer to the [License File](LICENSE).\n\nIf you have any questions or need further assistance, feel free to reach out to us. Happy coding with Muzu!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyldrmzffr%2Fmuzu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyldrmzffr%2Fmuzu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyldrmzffr%2Fmuzu/lists"}