> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formal.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Smart Routing

> How to use smart routing to connect to multiple resources through a single port

Smart routing is a feature that allows you to connect to multiple resources through a single port, e.g. when a "Technology" listener is configured for the Connector.

This is particularly useful when you want to simplify your connection management and reduce the number of ports you need to open.

#### PostgreSQL

For PostgreSQL, use `<db_name>@<resource-name>` as database name to specify the resource.

Example:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
psql -h HOSTNAME_OF_CONNECTOR -p 5432 -d DATABASE_NAME@RESOURCE_NAME -U idp:formal:human:john@joinformal.com
```

#### MySQL

For MySQL, use `<db_name>@<resource-name>` as database name to specify the resource.

Example:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
mysql -h HOSTNAME_OF_CONNECTOR -P 3306 -u 'idp:formal:human:john@joinformal.com' -p DATABASE_NAME@RESOURCE_NAME
```

#### MongoDB

For MongoDB, use `formal_resource_name=<resource-name>` as appName name to specify the resource.

Example:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
mongosh "mongodb://HOSTNAME_OF_CONNECTOR:27017/?appName=formal_resource_name=RESOURCE_NAME"
```

#### HTTP

For HTTP use `<resource-name>.<host>:<port>` to specify the resource.

> [!WARNING]
>
> Make sure your DNS entries are properly configured to handle the subdomain routing, i.e. that `*.<host>` targets your Connector.

Example:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
curl https://RESOURCE_NAME.HOSTNAME_OF_CONNECTOR:443/api/endpoint
```

> [!NOTE]
>
> S3 does not support smart routing. An S3 listener serves exactly one S3 resource.

#### ClickHouse

ClickHouse smart routing is available through the HTTP interface. Configure a technology listener that matches multiple ClickHouse resources.

Prefix the Connector hostname with the resource name:

`<resource-name>.<host>:<port>`

Example:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
curl --user 'FORMAL_USERNAME:FORMAL_ACCESS_TOKEN' \
  --data-binary 'SELECT 1' \
  https://RESOURCE_NAME.HOSTNAME_OF_CONNECTOR:8444/
```

> [!WARNING]
>
> Make sure DNS resolves `*.<host>` to the Connector. The Connector selects the resource from the HTTP `Host` header.

#### gRPC

For gRPC, prefix the Connector hostname with the resource name:

`<resource-name>.<host>:<port>`

Example:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
grpc_cli call RESOURCE_NAME.HOSTNAME_OF_CONNECTOR:PORT GRPC_METHOD_NAME \
  --metadata "x-formal-user-username:FORMAL_USERNAME:x-formal-user-password:FORMAL_ACCESS_TOKEN"
```

If your gRPC client dials one address and sends a separate authority or server
name, set that value to `RESOURCE_NAME.HOSTNAME_OF_CONNECTOR`.

> [!WARNING]
>
> Make sure your DNS entries are properly configured to handle the subdomain routing, i.e. that `*.<host>` targets your Connector.

#### Redis

For Redis, use `<resource-name>.<host>` as the TLS server name to specify the resource. The Connector reads it from the TLS handshake, so the connection must use TLS.

Example:

```bash theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
redis-cli -h RESOURCE_NAME.HOSTNAME_OF_CONNECTOR -p PORT --tls \
  --sni RESOURCE_NAME.HOSTNAME_OF_CONNECTOR \
  --user FORMAL_USERNAME --pass FORMAL_ACCESS_TOKEN
```

Most Redis client libraries derive the TLS server name from the hostname they connect to. Pointing them at `RESOURCE_NAME.HOSTNAME_OF_CONNECTOR` is therefore enough. redis-cli is an exception, and requires `--sni` to be passed explicitly.

> [!WARNING]
>
> Make sure DNS entries are properly configured to handle the subdomain routing, i.e. that `*.<host>` targets the Connector.


## Related topics

- [ClickHouse](https://docs.formal.ai/docs/guides/core-concepts/resources/clickhouse.md)
- [gRPC](https://docs.formal.ai/docs/guides/core-concepts/resources/grpc.md)
- [MongoDB](https://docs.formal.ai/docs/guides/core-concepts/resources/mongodb.md)
- [MySQL](https://docs.formal.ai/docs/guides/core-concepts/resources/mysql.md)
- [Redis](https://docs.formal.ai/docs/guides/core-concepts/resources/redis.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.