---
title: Read the first value of a request header
summary: Return the first value of a request header, or an empty string, without ever throwing.
status: draft
owner: andmil
last_reviewed: 2026-09-15
library: SAIF.Web.API
reference_type: package
operation_id: OP-10
trigger: OP-05 (Compose the trace and log message), step 2, and any consumer call.
---

# Read the first value of a request header

`HttpRequestExtensions.TryGetFirstHeader` reads the first value of a request header without ever throwing.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-10 |
| **Trigger** | [Compose the trace and log message](op-05-compose-the-trace-and-log-message.md), step 2, and any consumer call. |
| **Inputs** | `HttpRequestMessage`, header key |
| **Outputs** | `string` |
| **Primary components** | `HttpRequestExtensions.TryGetFirstHeader(this HttpRequestMessage, string)` |
| **Entry point** | `src/SAIF.Web.API/HttpRequestExtensions.cs` |

## Steps

1. If `request.Headers != null` and `request.Headers.TryGetValues(key, out values)` succeeds, return `values.FirstOrDefault()` ([BR-WEBAPI-019](../business-rules.md#br-webapi-019-header-reads-never-throw)).
   - May return `null` if the header exists with an empty value collection.*
2. Otherwise return `""` ([BR-WEBAPI-019](../business-rules.md#br-webapi-019-header-reads-never-throw)).
   - Never throws on a missing header.

## Process flow

```mermaid
flowchart TD
	Start(["Called from OP-05 step<br>2, or any consumer"]) --> HasHeaders{"Headers != null and<br>TryGetValues succeeds?"}
	HasHeaders -->|Yes| First["return<br>values.FirstOrDefault()"]
	HasHeaders -->|No| Empty["return \"\""]
```

## Failure and edge-case behavior
- Never throws; a header present with an empty value collection can yield `null` rather than `""`.*

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## Sources
- `src/SAIF.Web.API/HttpRequestExtensions.cs`
