grpc-java
grpc-java copied to clipboard
Add grpc request validator
Hi, i'm grpc user. I feel uncomfortable when request validation.
request validation code
class HelloRequestGrpcService : HelloServiceGrpcKt.HelloServiceCoroutineImplBase() {
override suspend fun hello(request: HelloRequest): HelloResponse {
if(request.message != “valid request”) {
throw StatusRuntimeException…
}
// or
val isValid = request.isValid()
if(!isValid) throw StatusRuntimeException…
return super.hello(request)
}
}
fun HelloRequest.isValid(): Boolean {
return true
}
I think responsibilities should be distributed. I wish validator like spring custom validator I think become neat code like example code If exists validator.
class HelloRequestGrpcService : HelloServiceGrpcKt.HelloServiceCoroutineImplBase() {
override suspend fun hello(request: HelloRequest): HelloResponse {
return super.hello(request)
}
}
Do you have any plan ? If you have a plan, could you please review PR
Comments added to the PR https://github.com/grpc/grpc-java/pull/9323
https://github.com/grpc/grpc-java/pull/9323#issuecomment-1178336254