+++
title = "Implement API client module — typed fetch wrappers for all quotesdb-api endpoints"
priority = 7
status = "todo"
ticket_type = "task"
dependencies = ["c3503b", "93515e"]
+++
The `quotesdb` UI is a Yew (Rust → Wasm) single-page app compiled by Trunk and hosted on Cloudflare Pages. It communicates with the backend API via `fetch` calls. Source lives in `src/bin/ui/`. Run with `trunk serve` for local development.
The API client module provides typed fetch wrappers around all quotesdb-api endpoints. The UI calls these functions from page components rather than making raw fetch calls directly.
Implement `src/bin/ui/api.rs` (or `src/bin/ui/client.rs`) with async functions for each endpoint:
- `list_quotes(page, author, tag) -> Result`
- `get_quote(id) -> Result`
- `get_random_quote() -> Result`
- `create_quote(body) -> Result`
- `update_quote(id, auth_code, body) -> Result`
- `delete_quote(id, auth_code) -> Result<()>`
Each function sets the appropriate headers (including `X-Auth-Code` where needed) and deserialises the response.
- Use `gloo::net::http` or `web_sys::fetch` for HTTP requests (not reqwest — not available in WASM).
- Resolve TRIAGE ticket a9534d (CORS and Trunk proxy config) — during `trunk serve`, the API URL may differ.
- All functions must be `async` and return `Result` with a meaningful error type.
- The base URL should be configurable (env var at compile time or from `window.location.origin`).
From the `quotesdb/` directory:
```sh
trunk build
```
`feat(quotesdb): implement typed API client module for all quotesdb-api endpoints`