index: "Intro",
"-- other": {
type: "separator",
title: "Others",
},
"db-service": "DB Service",
example: {
title: "Examples ↗",
href: "https://github.com/chakhsu/grpcity/tree/main/example",
newWindow: true,
},
changelog: {
title: "Changelog ↗",
href: "https://github.com/chakhsu/grpcity/releases",
newWindow: true,
},
}
Import Loader
./server.js
import loader from "./loader.js"
Implement Greeter
Create Greeter
and implement the sayGreet
method:
./server.js
class Greeter {
constructor() {
this.count = 0
}
async sayGreet(call) {
const { name } = call.request
this.count++
return {
message: `hello ${name || "world"} by Greeter`,
count: this.count,
}
}
}
Advanced
Please select one of the following guides for a deeper understanding and learning:
options={[
["name", "String", "Required, service name including package name"],
[
"implementation",
"Object",
"Required, object or class containing methods defined in service rpc",
],
["options", "Object", "Optional, { exclude, inherit }"],
]}
/>
Heading
With bg
⚠️
Warning
code looking
enter a
enter b
enter c
rpc-method()
exit c
exit b
exit a
Terminal
{
path: '/helloworld.Greeter/SayGreet',
method: {
requestStream: false,
responseStream: false,
metadata: Metadata { internalRepr: [Map], options: {} },
options: { deadline: 2024-01-16T16:22:11.836Z }
},
request: { name: 'greeter' }
}
Field Name | Valid Values | Description |
---|---|---|
keepCase | true or false | Preserve field names. By default, they are changed to camel case. |
longs | String or Number | Type used to represent long values. Default is the Long object type. |
enums | String | Type used to represent enum values. Default is a numeric type. |
bytes | Array or String | Type used to represent bytes values. Default is Buffer . |
defaults | true or false | Set default values on the output object. Default is false . |
arrays | true or false | Set empty arrays for missing array values, even if defaults is false . Default is false . |
objects | true or false | Set empty objects for missing object values, even if defaults is false . Default is false . |
oneofs | true or false | Set virtual oneof properties as field names. Default is false . |
json | true or false | Represent Infinity and NaN as strings in float fields and automatically decode google.protobuf.Any values. Default is false . |
includeDirs | Array of strings | List of search paths for imported .proto files. |
Terminal
.
└── certs
├── ca.crt
├── ca.key
├── client.crt
├── client.csr
├── client.key
├── server.crt
├── server.csr
└── server.key
./loader.js
import { ProtoLoader } from "grpcity"
import path from "node:path"
import { fileURLToPath } from "node:url"
// __dirname for esm
const __dirname = path.dirname(fileURLToPath(import.meta.url))
export default new ProtoLoader({
location: path.resolve(__dirname, "./"),
files: ["stream.proto"],
})