{"library":"mali","title":"Mali: Minimalistic gRPC Framework","description":"Mali is a minimalistic, middleware-based gRPC microservice framework for Node.js, designed to simplify the creation of gRPC servers. It operates similarly to popular HTTP frameworks like Koa or Express, leveraging a context object (`ctx`) for request and response handling within a cascading middleware pattern. The current stable version is `0.47.1`. The project maintains a regular, albeit not rapid, release cadence, primarily focusing on dependency updates, performance improvements, and bug fixes, as seen in recent versions like `v0.47.0` and `v0.46.0`. Its key differentiator lies in its commitment to minimalism and a familiar middleware API for gRPC, abstracting away some of the complexities of the underlying `@grpc/grpc-js` and `@grpc/proto-loader` libraries, which are required as peer dependencies. It also ships with TypeScript types.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install mali"],"cli":null},"imports":["import { Mali } from 'mali';","import type { Context } from 'mali';","import { App } from 'mali';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const Mali = require('mali');\nconst path = require('path');\nconst fs = require('fs');\n\n// A minimalistic gRPC service definition\nconst PROTO_CONTENT = `\n  syntax = \"proto3\";\n\n  package helloworld;\n\n  service Greeter {\n    rpc SayHello (HelloRequest) returns (HelloReply) {}\n  }\n\n  message HelloRequest {\n    string name = 1;\n  }\n\n  message HelloReply {\n    string message = 1;\n  }\n`;\n\n// Write the proto content to a temporary file for Mali to load\nconst PROTO_PATH = path.resolve(__dirname, 'helloworld.proto');\nfs.writeFileSync(PROTO_PATH, PROTO_CONTENT);\n\nfunction sayHello (ctx) {\n  ctx.res = { message: `Hello ${ctx.req.name || 'World'}` };\n  console.log(`Handled SayHello for ${ctx.req.name || 'World'}`);\n}\n\nasync function main () {\n  const app = new Mali(PROTO_PATH);\n  app.use({ sayHello });\n  const port = '0.0.0.0:50051';\n  app.start(port);\n  console.log(`gRPC server running on ${port}`);\n\n  // Basic client to test the server (optional, for demonstration)\n  const grpc = require('@grpc/grpc-js');\n  const protoLoader = require('@grpc/proto-loader');\n  const packageDefinition = protoLoader.loadSync(PROTO_PATH, { keepCase: true, longs: String, enums: String, defaults: true, oneofs: true });\n  const hello_proto = grpc.loadPackageDefinition(packageDefinition).helloworld;\n  const client = new hello_proto.Greeter(port, grpc.credentials.createInsecure());\n\n  client.sayHello({ name: 'Mali User' }, (err, response) => {\n    if (err) {\n      console.error('Client error:', err);\n    } else {\n      console.log('Client received:', response.message);\n    }\n    // Clean up temporary proto file and stop the server for a real test\n    fs.unlinkSync(PROTO_PATH);\n    app.shutdown();\n  });\n}\n\nmain().catch(console.error);\n","lang":"javascript","description":"This quickstart demonstrates setting up a basic Mali gRPC server, defining a simple 'Greeter' service with a 'SayHello' method, and then creating a client to interact with it. It includes the necessary proto definition and server startup/shutdown.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}