Skip to content

refactor: replace FromResponse trait with fetch_inner + fetch_conditi… - #23

Merged
gruuya merged 2 commits into
splitgraph:rest-cache-primitivesfrom
JanKaul:refactor-fetch-no-from-response-trait
Jul 15, 2026
Merged

refactor: replace FromResponse trait with fetch_inner + fetch_conditi…#23
gruuya merged 2 commits into
splitgraph:rest-cache-primitivesfrom
JanKaul:refactor-fetch-no-from-response-trait

Conversation

@JanKaul

@JanKaul JanKaul commented Jul 15, 2026

Copy link
Copy Markdown

Builds on JanKaul#372.

I would like to avoid the FromResponse trait. I refactored the same logic into a fetch_inner method and created a fetch_conditional wrapper. I think it should solve the same issue.

Additionally extended the Conditional struct to include also other response headers. To be able to use it for vended-credentials.

…onal

- Extract HTTP mechanics into private fetch_inner returning reqwest::Response
- fetch becomes a thin wrapper (T: DeserializeOwned), absorbing fetch_empty
- fetch_conditional returns Conditional<T> for 304-aware endpoints
- Conditional::Modified now carries the full HeaderMap instead of a single
  extracted etag string, letting callers access any response header
- load_table is non-generic, always returns Conditional<LoadTableResult>
- No FromResponse trait needed; no fetch_empty function needed

@gruuya gruuya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestions!

Fwiw, my thinking for the (optional) follow-up to this was either:

  1. expose a load_tabular_cached method in the catalog, that would accept etag as another argument (thus delegating caching entirely to the user), or
  2. have RestCatalog carry optional metadata cache, exposed via a trait (so that users can control storage/limits/TTL/eviction), but ultimately the cache is owned by the RestCatalog instance. When unset (None) it uses the regular fetch, and when Some` it uses the conditional one.

I guess this is still doable even with catalog_api_api::load_table always returning a result wrapped in Conditional.

Comment thread catalogs/iceberg-rest-catalog/src/apis/catalog_api_api.rs
load_table returns LoadTableResult directly — no wrapping, ergonomic for
callers that don't need cache semantics.

load_table_conditional returns Conditional<LoadTableResult> and is the
right call when passing If-None-Match; it can return NotModified.

This avoids surprising callers of load_table with a Conditional return
type when no If-None-Match header was sent.
@gruuya
gruuya merged commit 214a1ae into splitgraph:rest-cache-primitives Jul 15, 2026
@JanKaul

JanKaul commented Jul 15, 2026

Copy link
Copy Markdown
Author

I really like the second approach. I think it makes sense that the metadata cache should be tied to the catalog instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants