# References

## Introduction

References are defined inside a template definition. References contain two parts. The resource to be targeted and the path within the given resource.

```
{{ input:message }}
```

{% hint style="info" %}
A error is returned if the given resource/path has not been found or when types mismatch
{% endhint %}

## Resources

Calls, inputs and outputs are resources inside a flow. All resources could be referenced. Below is a simple flow with the following resources available: input and user.

```bash
flow "fetch" {
	input "schema.Query" {}
	
	resource "user" {}
	
	output "schema.Result" {
		message = "{{ input:message }}"
	}
}
```

### Properties

Inside a resource are properties available. The available properties inside a resource might differ. Below are the available properties within different resource types. The request property is always used as default if no property is defined.

```bash
{{ call.request:prop }}
```

| Input         | Call           |
| ------------- | -------------- |
| header        | header         |
| ***request*** | request        |
|               | ***response*** |

```bash
flow "fetch" {
	input "schema.Query" {}
	
	resource "schema" {
		request "schema.User" "GetUser" {
			message = "{{ input:message }}"
		}
	}
	
	output "schema.Result" {
		message = "{{ user.request:message }}"
	}
}
```

## Path

Properties and nested properties are simply defined through the reference path.

```bash
flow "create" {
	input "schema.CreateUser" {}

	resource "user" {
		request "schema.User" "New" {
			message "address" {
				street = "{{ input:street }}"
			}
		}
	}
	
	output "schema.User" {
		message "address" {
			street = "{{ user.request:address.street }}"
		}
	}
}
```

### Message reference

Complete messages could be referenced if the content is mappable with the target property. This could be useful to reference complete objects without having to define a object over and over again.

Inside the example below is the address message copied to the output.

```bash
flow "create" {
	input "schema.CreateUser" {}

	resource "user" {
		request "proto.User" "New" {
			message "address" {
				street = "{{ input:street }}"
			}
		}
	}
	
	output "schema.User" {
		address = "{{ user.request:address }}"
	}
}
```

### Self reference

Sometimes you want to copy the entire message of a given resource. This is similar to message references but could be applied to entire resources instead of properties.

Inside the example below is the user request message copied to the output inside the user property.

```bash
flow "create" {
	input "schema.CreateUser" {}

	resource "user" {
		request "schema.User" "New" {
			message "address" {
				street = "{{ input:street }}"
			}
		}
	}
	
	output "schema.UserDetails" {
		user = "{{ user.request:. }}"
	}
}
```

## Nested values

Nested values (messages) store properties, nested values could be created inside nested values.

```bash
message "nested" {
    value = "{{ input:message }}"
}
```

## Repeated values

Repeated messages accept two labels the first one is its property name and the second one is the resource reference. If a repeated message is kept empty the whole message is attempted to be copied.

```bash
repeated "destination" "input:destination" {
    country = "{{ input:destination.country }}"
}
```

{% hint style="warning" %}
Currently are only repeated messages supported, repeated values are planned for in the future
{% endhint %}

## Header values

Headers could be defined and passed similar to message properties. Header values are accessed through the `header` resource property.

```bash
input "schema.Object" {
    header = ["Authorization"]
}

resource "authenticate" {
    request "service" "Auth" {
        header {
            Authorization = "{{ input.header:Authorization }}"
        }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jexia.gitbook.io/semaphore/cookbook/flows/references.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
