http-client-abstraction
Use @repo/api-client SDK hooks (preferred) or raw fetch directly in domain-specific HTTP implementations (extension app only) — no generic HTTP wrapper layer needed
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-04
- Stars
- ★ 41
- Forks
- 0
01 前言 Front Matter
- name
- http-client-abstraction
- description
- Use @repo/api-client SDK hooks (preferred) or raw fetch directly in domain-specific HTTP implementations (extension app only) — no generic HTTP wrapper layer needed
03 SKILL.md 正文
HTTP Client Abstraction
The HTTP client pattern applies only in the extension app (client-side). The web app uses @repo/api-client via server functions (server-side fetch).
Primary Pattern: Use @repo/api-client SDK Directly
The @repo/api-client SDK uses fetch under the hood, so no manual HTTP implementations are needed. Use api.* for programmatic calls (background scripts, services) and auto-generated hooks for React components:
// ✅ DO — Use api.* for programmatic HTTP calls
import { api } from "@repo/api-client";
async function deleteGuide(guideId: string) {
const response = await api.guides.deleteGuide(guideId);
if (response.status !== 200) {
console.error("Failed to delete guide:", response.data);
return null;
}
return response.data.guide;
}
// ✅ DO — Use auto-generated hooks in React components
import { useGetAllGuides, useCreateGuide } from "@repo/api-client";
function GuideManager() {
const { data, isLoading } = useGetAllGuides();
const createMutation = useCreateGuide({
mutation: {
onSuccess: () => { /* handle success */ },
},
});
// ...
}
✅ DO — Use api-client as the default (both api.* and hooks)
❌ DON'T — Write manual http-{domain}.service.ts files for endpoints covered by api-client
Fallback Pattern: Direct fetch (Non-api-client Domains)
For endpoints not covered by @repo/api-client, use raw fetch directly. No generic HTTP wrapper layer needed.
// Non-api-client endpoint (fallback only)
async function callExternalApi(url: string, body: unknown) {
const response = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (!response.ok) {
throw new Error(`Failed: ${response.status} ${response.statusText}`);
}
const data = await response.json();
// Validate with Zod if needed
return data;
}
URL Construction Conventions (Fallback)
// ✅ DO — Append params as URL segments
`${baseUrl}/${resourceId}/screenshot`
// ✅ DO — Append query strings
`${baseUrl}?cursor=${cursor}`
Rules
✅ DO
- Use
@repo/api-client(bothapi.*and hooks) as the default HTTP client pattern in the extension - For non-api-client domains: use
fetchdirectly - Import types from
@repo/api-clientor from@/modelsfor fallback domains
❌ DON'T
- Don't write
http-{domain}.service.tsfiles — use@repo/api-clientdirectly - Don't create factory functions for HTTP calls — the SDK handles everything
- Don't create generic HTTP wrapper layers — keep it simple with direct
fetchcalls for fallback domains
04 同仓库更多 Skills
typst
Typst document creation and package development. Use when: (1) Working with .typ files, (2) User mentions typst, typst.toml, or typst-cli, (3) Creating or using Typst packages, (4) Developing document templates, (5) Converting Markdown/LaTeX to Typst
shadcn
Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI. Provides project context, component docs, and usage examples. Applies when working with shadcn/ui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for "shadcn init", "create an app with --preset", or "switch to --preset".
handoff
Compact the current conversation into a handoff document for another agent to pick up.
grilling
Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.
grill-me
A relentless interview to sharpen a plan or design.
dont-waffle
Use this skill when answering questions, explaining concepts, writing technical responses, reviewing code, or helping with development tasks. Communicate in clear, simple, standard English. Keep answers concise and focused, remove unnecessary filler and repetition, explain technical ideas in plain language, and structure information so it is easy to read and understand. When showing code, present it clearly with enough context for the developer to understand what it does and where it belongs.