{"_id":"@apachedubbo/dubbo-fastify","name":"@apachedubbo/dubbo-fastify","dist-tags":{"alpha":"3.0.0-alpha","latest":"3.0.0-alpha"},"versions":{"3.0.0-alpha":{"name":"@apachedubbo/dubbo-fastify","version":"3.0.0-alpha","license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/apache/dubbo-js.git","directory":"packages/dubbo-fastify"},"sideEffects":false,"scripts":{"clean":"rm -rf ./dist/cjs/* ./dist/esm/* ./dist/types/*","build":"npm run build:cjs && npm run build:esm+types","build:cjs":"tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'","build:esm+types":"tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/types"},"main":"./dist/cjs/index.js","type":"module","types":"./dist/types/index.d.ts","exports":{"types":"./dist/types/index.d.ts","import":"./dist/esm/index.js","require":"./dist/cjs/index.js"},"engines":{"node":">=16.0.0"},"dependencies":{"@apachedubbo/dubbo":"3.0.0-alpha","@apachedubbo/dubbo-node":"3.0.0-alpha","fastify":"^4.17.0"},"peerDependencies":{"@bufbuild/protobuf":"^1.2.1"},"gitHead":"dd9eba1b7b4c5d306fc8275537694cca02ad7975","description":"Dubbo is a family of libraries for building and consuming APIs on different languages and platforms, and [@apachedubbo/dubbo](https://www.npmjs.com/package/@apachedubbo/dubbo) brings type-safe APIs with Protobuf to TypeScript.","bugs":{"url":"https://github.com/apache/dubbo-js/issues"},"homepage":"https://github.com/apache/dubbo-js#readme","_id":"@apachedubbo/dubbo-fastify@3.0.0-alpha","_nodeVersion":"18.16.1","_npmVersion":"9.5.1","dist":{"integrity":"sha512-xbcEQQjTx4aHuBVJzK7pHOXD9DzFBI/tiF8o28o9Gvhr1HjwhOpmSZ1hFR1J7+WLh34mT5/SdNeoxH7dGtBsgg==","shasum":"84a0ee1960cedee649a89d410207096958359402","tarball":"https://registry.npmjs.org/@apachedubbo/dubbo-fastify/-/dubbo-fastify-3.0.0-alpha.tgz","fileCount":9,"unpackedSize":15570,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG/AUybn9bPEp36ae97TwhMdY672Cq2P3l50W1qErYdiAiAG04zFFPlHih0EaQp2KtRGKz/q4/vFAfTwKKiTaLDCSg=="}]},"_npmUser":{"name":"jianyi-gronk","email":"jianyi_gronk@163.com"},"directories":{},"maintainers":[{"name":"jianyi-gronk","email":"jianyi_gronk@163.com"},{"name":"apache-dubbo","email":"dubbo.alibaba@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dubbo-fastify_3.0.0-alpha_1694061607994_0.2632760933639282"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-07T04:40:07.927Z","3.0.0-alpha":"2023-09-07T04:40:08.146Z","modified":"2023-09-07T04:40:08.458Z"},"maintainers":[{"name":"jianyi-gronk","email":"jianyi_gronk@163.com"},{"name":"apache-dubbo","email":"dubbo.alibaba@gmail.com"}],"description":"Dubbo is a family of libraries for building and consuming APIs on different languages and platforms, and [@apachedubbo/dubbo](https://www.npmjs.com/package/@apachedubbo/dubbo) brings type-safe APIs with Protobuf to TypeScript.","homepage":"https://github.com/apache/dubbo-js#readme","repository":{"type":"git","url":"git+https://github.com/apache/dubbo-js.git","directory":"packages/dubbo-fastify"},"bugs":{"url":"https://github.com/apache/dubbo-js/issues"},"license":"Apache-2.0","readme":"# @apachedubbo/dubbo-fastify\n\nDubbo is a family of libraries for building and consuming APIs on different languages and platforms, and\n[@apachedubbo/dubbo](https://www.npmjs.com/package/@apachedubbo/dubbo) brings type-safe APIs with Protobuf to\nTypeScript.\n\n`@apachedubbo/dubbo-fastify` provides a plugin for [fastify](https://www.fastify.io/), the fast and \nlow overhead web framework, for Node.js.\n\n### fastifyDubboPlugin()\n\nPlug your Dubbo RPCs into a fastify server.\n\n```ts\n// connect.ts\nimport { DubboRouter } from \"@apachedubbo/dubbo\";\n\nexport default function(router: DubboRouter) {\n  // implement rpc Say(SayRequest) returns (SayResponse)\n  router.rpc(ElizaService, ElizaService.methods.say, async (req) => ({\n    sentence: `you said: ${req.sentence}`,\n  }));\n}\n```\n\n```diff\n// server.ts\nimport { fastify } from \"fastify\";\n+ import routes from \"dubbo\";\n+ import { fastifyDubboPlugin } from \"@apachedubbo/dubbo-fastify\";\n\nconst server = fastify({\n  http2: true,\n});\n\n+ await server.register(fastifyDubboPlugin, { \n+  routes \n+ });\n\nawait server.listen({\n  host: \"localhost\",\n  port: 8080,\n});\n```\n\nWith that server running, you can make requests with any gRPC, gRPC-Web, or Dubbo client.\n\n`buf curl` with the gRPC protocol:\n\n```bash\nbuf curl --schema buf.build/bufbuild/eliza \\\n  --protocol grpc --http2-prior-knowledge \\\n  -d '{\"sentence\": \"I feel happy.\"}' \\\n  http://localhost:8080/buf.connect.demo.eliza.v1.ElizaService/Say\n```\n\n`curl` with the Dubbo protocol:\n\n```bash\ncurl \\\n    --header \"Content-Type: application/json\" \\\n    --data '{\"sentence\": \"I feel happy.\"}' \\\n    --http2-prior-knowledge \\\n    http://localhost:8080/buf.connect.demo.eliza.v1.ElizaService/Say\n```\n\nNode.js with the gRPC protocol (using a transport from [@apachedubbo/dubbo-node](https://www.npmjs.com/package/@apachedubbo/dubbo-node)):\n\n```ts\nimport { createPromiseClient } from \"@apachedubbo/dubbo\";\nimport { createGrpcTransport } from \"@apachedubbo/dubbo-node\";\nimport { ElizaService } from \"./gen/eliza_dubbo.js\";\n\nconst transport = createGrpcTransport({\n  baseUrl: \"http://localhost:8080\",\n  httpVersion: \"2\",\n});\n\nconst client = createPromiseClient(ElizaService, transport);\nconst { sentence } = await client.say({ sentence: \"I feel happy.\" });\nconsole.log(sentence) // you said: I feel happy.\n```\n\nA client for the web browser actually looks identical to this example - it would\nsimply use `createDubboTransport` from [@apachedubbo/dubbo-web](https://www.npmjs.com/package/@apachedubbo/dubbo-web) \ninstead.\n\n\n## Getting started\n\nTo get started with Dubbo, head over to the [docs](https://cn.dubbo.apache.org/zh-cn/overview/quickstart/)\nfor a tutorial, or take a look at [our example](https://github.com/apache/dubbo-js/tree/dubbo3/example/). \n","readmeFilename":"README.md"}