// Module included in the following assemblies:
//
// * networking/ingress_load_balancing/configuring_ingress_cluster_traffic/routing-grpc-requests-to-services.adoc

:_mod-docs-content-type: PROCEDURE
[id="applying-processing-filters-grpc-requests_{context}"]
= Apply processing filters to gRPC requests

[role="_abstract"]
When a gRPC request hits your route, you can apply processing filters to modify the request or response before the traffic reaches your backend. 

You can define optional filters within your routing rules to apply processing directives, such as request and response header modifiers or traffic mirroring. You can also specify rule-scoped filters directly within your backend references. 

Because the data-plane behavior is provided by {SMProductName}, you must validate specific feature support, such as filter capabilities and header matching, against your installed Service Mesh release.

.Prerequisites

* You have access to the cluster as a user with the `cluster-admin` role.
* You have installed the {oc-first}.
* You have installed {SMProductName}.

.Procedure

. Create or edit a `GRPCRoute` YAML file to include your desired processing directives under the `spec.rules.filters` field. 
+
--
The following example demonstrates a complete `GRPCRoute` resource configured with a filter that adds a custom request header before routing to the backend service:

[source,yaml]
----
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
  name: grpc-filter-example
  namespace: my-application
spec:
  parentRefs:
  - name: my-gateway
    namespace: openshift-ingress
  hostnames:
  - "example.com"
  rules:
  - filters:
    - type: RequestHeaderModifier
      requestHeaderModifier:
        add:
        - name: custom-grpc-header
          value: my-custom-value
    backendRefs:
    - name: greeter-service
      port: 50051
----
* `parentRefs` attaches the route to a specific Gateway.
* `hostnames` limits the route to requests intended for `"example.com"`.
* `filters` specifies the processing logic. In this example, the `RequestHeaderModifier` adds a custom header to the gRPC request before it reaches the backend.
* `backendRefs` directs the modified traffic to the `greeter-service` backend on port `50051`.
--

. Apply the `GRPCRoute` resource by running the following command:
+
[source,terminal]
----
$ oc apply -f <filename>.yaml
----