Function tonic::service::interceptor_fn[][src]

pub fn interceptor_fn<F>(f: F) -> InterceptorFn<F> where
    F: FnMut(Request<()>) -> Result<Request<()>, Status>, 
Expand description

Create a new interceptor from a function.

gRPC interceptors are similar to middleware but have less flexibility. An interceptor allows you to do two main things, one is to add/remove/check items in the MetadataMap of each request. Two, cancel a request with a Status.

An interceptor can be used on both the server and client side through the tonic-build crate’s generated structs.

See the interceptor example for more details.

If you need more powerful middleware, tower is the recommended approach. You can find examples of how to use tower with tonic here.

Additionally, interceptors is not the recommended way to add logging to your service. For that a tower middleware is more appropriate since it can also act on the response. For example tower-http’s Trace middleware supports gRPC out of the box.