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

:_mod-docs-content-type: PROCEDURE
[id="creating-httproute_{context}"]
= Creating a basic HTTPRoute custom resource

[role="_abstract"]
To direct incoming network traffic from a gateway to your backend applications, you must create an HTTPRoute custom resource (CR). The resource specifies the hostnames the route handles and binds them to a parent `Gateway` CR.

.Prerequisites

* You created a target backend service.
* You know the name and namespace of the parent `Gateway` CR.

.Procedure

. Create an `HTTPRoute` CR file that references your parent gateway, application hostnames, and backend service, and save it as `httproute.yaml`:
+
[source,yaml]
----
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: sample-route
  namespace: my-application
spec:
  parentRefs:
  - name: generic-gateway
    namespace: openshift-ingress
  hostnames:
  - app1.example.com
  - app2.example.com
  rules:
  - backendRefs:
    - name: application-backend
      port: 8080
----
+
* You must include application hostnames and a `backendRef` rule that points to your backend service.
* If your `HTTPRoute` and `Gateway` CRs are deployed in different namespaces, the `Gateway` CR listener must be configured to allow cross-namespace routes. You must set `allowedRoutes.namespaces.from: All` in the `Gateway` CR.

. Apply the `HTTPRoute` CR file to your cluster:
+
[source,terminal]
----
$ oc apply -f httproute.yaml
----

.Verification

* Verify that the `HTTPRoute` CR was successfully created:
+
[source,terminal]
----
$ oc get httproute <sample_route> -n <my_application>
----
+
.Example output
[source,terminal]
----
NAME           HOSTNAMES                                 AGE
sample-route   ["app1.example.com","app2.example.com"]   45s
----