Minimal gRPC users CRUD example for Sword using grpc and an in-memory store.
cargo run -p sword-grpc-exampleusers.UserServicegrpc.health.v1.Healthgrpc.reflection.v1.ServerReflection(enabled bygrpc-reflectionfeature)
users.UserService/ListUsersusers.UserService/StreamUsersusers.UserService/CreateUserusers.UserService/GetUserusers.UserService/UpdateUserusers.UserService/DeleteUsergrpc.health.v1.Health/Check
Start the server (see Run) and use grpcurl. Reflection is enabled, so services are discovered automatically.
List services and methods:
grpcurl -plaintext 127.0.0.1:50051 list
grpcurl -plaintext 127.0.0.1:50051 list users.UserServiceusers.UserService methods require an authorization metadata value — replace <token> (any value works):
grpcurl -plaintext -H "authorization: <token>" -d '{}' 127.0.0.1:50051 users.UserService/ListUsers
grpcurl -plaintext -H "authorization: <token>" \
-d '{"username": "<username>", "password": "<password>"}' \
127.0.0.1:50051 users.UserService/CreateUser
grpcurl -plaintext -H "authorization: <token>" -d '{"id": "<id>"}' 127.0.0.1:50051 users.UserService/GetUser
grpcurl -plaintext -H "authorization: <token>" -d '{}' 127.0.0.1:50051 users.UserService/StreamUsersHealth check (no authorization required):
grpcurl -plaintext -d '{}' 127.0.0.1:50051 grpc.health.v1.Health/Check- UserService methods expect
authorizationmetadata. - Server default address is
127.0.0.1:50051. - If the binary is built with the
grpc-reflectionfeature,grpcurl listincludes health and users services. - Reflection metadata is registered automatically by Sword from
build.rswhen generatingsword_descriptor_set.bin.