# Integration patterns
`requisite` is most effective when wrappers appear at subsystem boundaries and
requirements appear in receiving function signatures.
## HTTP input to repository call
Create `Untrusted` values in the handler, parse them with `try_sanitize`, and
pass trusted representations to the repository:
```rust
use requisite::prelude::*;
fn handle_customer(raw_id: String) -> Result<Customer, AppError> {
let raw = Tainted::<_, Untrusted>::from_input(raw_id);
let id = try_sanitize(raw, |value| {
value.parse::<u64>().map_err(AppError::from)
})?;
Ok(repository::load_customer(id)?)
}
mod repository {
use requisite::prelude::*;
pub fn load_customer(
id: Tainted<u64, Trusted>,
) -> Result<Customer, DatabaseError> {
query_customer(id.into_inner())
}
}
```
The repository API documents its input requirement in the type rather than in
a comment beside an unqualified `u64`.
## Cache access with stale recovery
Return `Fresh<T>` from a cache adapter so callers perform the TTL check where
they use the data:
```rust
fn cached_quote() -> Fresh<Quote> {
Fresh::fetch(read_quote(), Duration::from_secs(15))
}
match cached_quote().into_inner() {
Ok(quote) => price_order(quote),
Err(expired) => {
record_expired_quote(expired.value, expired.stale);
refresh_quote();
}
}
```
## Model output to an authorized action
Create `Confident<T>` where the model or forecast produces its score. Gate it
before calling an action that requires `Certain`:
```rust
fn classify(input: &Input) -> Result<Confident<Decision>, InvalidConfidence> {
let (decision, probability) = model_predict(input);
Confident::new(decision, probability)
}
fn commit(_proof: Certain, decision: Decision) {
write_decision(decision);
}
match classify(&input)?.gate() {
Gate::HighConfidence(proof, decision) => commit(proof, decision),
Gate::Likely(decision) => queue_review(decision),
Gate::Unsure(decision) => record_uncertain(decision),
}
```
## Error propagation
The constructors use ordinary `Result` values:
- `try_sanitize` returns the policy closure's error.
- `Confident::new` returns `InvalidConfidence`.
- `Thresholds::new` returns `InvalidThresholds`.
- `Fresh::fetched_at` returns `InvalidFetchTime`.
- Freshness reads return `Stale` or `StaleValue<T>`.
Application error enums can wrap these errors through `From` implementations or
an error helper such as `thiserror`.
## API design checklist
When adding `requisite` to a subsystem:
1. Create wrappers where raw data, scored values, or cached values enter.
2. Put the required state in the receiving function's parameter type.
3. Perform runtime checks close to the operation that consumes their result.
4. Keep policy closures and threshold configuration near the boundary they
define.
5. Preserve wrapper types across intermediate functions when those functions
have not satisfied the requirement themselves.