grpc-java icon indicating copy to clipboard operation
grpc-java copied to clipboard

Add grpc request validator

Open sangyongchoi opened this issue 2 years ago • 1 comments

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

sangyongchoi avatar Jun 29 '22 14:06 sangyongchoi

Comments added to the PR https://github.com/grpc/grpc-java/pull/9323

sanjaypujare avatar Jun 29 '22 16:06 sanjaypujare

https://github.com/grpc/grpc-java/pull/9323#issuecomment-1178336254

ejona86 avatar Aug 25 '22 18:08 ejona86