You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.2 KiB
Markdown
54 lines
2.2 KiB
Markdown
+++
|
|
title = "Implement API client module — typed fetch wrappers for all quotesdb-api endpoints"
|
|
priority = 7
|
|
status = "done"
|
|
ticket_type = "task"
|
|
dependencies = ["93515e"]
|
|
+++
|
|
|
|
<context>
|
|
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.
|
|
</context>
|
|
|
|
<goal>
|
|
Implement `src/bin/ui/api.rs` (or `src/bin/ui/client.rs`) with async functions for each endpoint:
|
|
- `list_quotes(page, author, tag) -> Result<ListResponse>`
|
|
- `get_quote(id) -> Result<Quote>`
|
|
- `get_random_quote() -> Result<Quote>`
|
|
- `create_quote(body) -> Result<CreateResponse>`
|
|
- `update_quote(id, auth_code, body) -> Result<Quote>`
|
|
- `delete_quote(id, auth_code) -> Result<()>`
|
|
|
|
Each function sets the appropriate headers (including `X-Auth-Code` where needed) and deserialises the response.
|
|
</goal>
|
|
|
|
<base-url-approach>
|
|
CORS/proxy resolved in triage a9534d: **Trunk proxy, relative URLs**.
|
|
|
|
- Use **relative URLs** (`/api/quotes`, `/api/quotes/random`, etc.) — no base URL configuration needed.
|
|
- In local dev, Trunk's `[[proxy]]` in `Trunk.toml` forwards `/api/*` to `localhost:3000` transparently.
|
|
- In production, Cloudflare routes `/api/*` to the Worker at the same domain.
|
|
- Do NOT use `window.location.origin` as a base URL — relative paths work everywhere.
|
|
- Do NOT add any CORS headers in the frontend — no cross-origin requests occur.
|
|
</base-url-approach>
|
|
|
|
<constraints>
|
|
- Use `gloo::net::http` for HTTP requests (not reqwest — not available in WASM).
|
|
- All API paths are relative: `/api/quotes`, `/api/quotes/{id}`, `/api/quotes/random`.
|
|
- All functions must be `async` and return `Result` with a meaningful error type.
|
|
- Do NOT configure a base URL — relative URLs are sufficient and correct.
|
|
</constraints>
|
|
|
|
<validation>
|
|
From the `quotesdb/` directory:
|
|
|
|
```sh
|
|
trunk build
|
|
```
|
|
</validation>
|
|
|
|
<commit>
|
|
`feat(quotesdb): implement typed API client module for all quotesdb-api endpoints`
|
|
</commit> |