api-client-patterns

A set of rules for building API clients, which are code components that communicate with backend services. It defines how to organise one client per service, name services, handle imports, and use schemas and HTTP requests.

In plain words
What is it for?
Use it when creating or maintaining TypeScript clients for services such as blog or user APIs, including their URLs, API keys, requests, and data types.
Why use it?
It prevents different backend connections from being organised and named inconsistently.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/charlee-x/effect-cursor-rules/api-client-patterns
Clone the repo
git clone --depth 1 https://github.com/CharLEE-X/effect-cursor-rules
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,387 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02387
Opus 5 $0.00000 $0.01193
Sonnet 5 $0.00000 $0.00477
Haiku 4.5 $0.00000 $0.00239

Measured yesterday against content hash 835ce53b913c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

api-client-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/api-client-patterns.mdc · 368 lines

How it starts

The opening of the file, as written. The whole thing — 368 lines — stays where its author put it; the contents beside it link to each section on GitHub.

API Client Patterns

Guidelines for creating and maintaining API clients that communicate with backend services in the T6C project.

Client Organization Principles

One Client Per API Service

  • ALWAYS create a dedicated client package for each API service
  • Client naming convention: {service-name}-api-client (e.g., blog-api-client, user-api-client)
  • Service class naming: {ServiceName}Service (e.g., BlogPostService, UserService)
// ✅ CORRECT - Dedicated client for blog API
export class BlogPostService extends E.Service<BlogPostService>()(
  '@web/BlogPostService',
  {
    dependencies: [FetchHttpClient.layer],
    effect: E.gen(function* () {
      const client = yield* createHttpClient({
        url: envVars.BLOG_SERVICE_URL,
        apiKey: envVars.BLOG_SERVICE_API_KEY,
      })

      return {
        // ... methods
      }
    }),
  },
) {}

Import Patterns

Standard Imports

  • Always use relative paths for internal imports
  • Import types with type keyword when used only for typing
  • Import schemas without type when used for encoding/decoding
// ✅ CORRECT - Import patterns
import {
  FetchHttpClient,
  HttpClientRequest,
  HttpClientResponse,
} from '@effect/platform'
import {
  BlogPost,
  BlogPostCategory,
  type BlogPostPatches,
  CreateBlogPostInput,
  GetBlogPageInput,
} from '@t6c/blog-domain'
import {
  type BlogPostId,
  PaginationSchema,
  type SearchParamsSchema,
  type UserId,
} from '@t6c/domain-common'
import { NotFoundError, createHttpClient } from '@t6c/lib-api'
import { Data, Effect as E, Layer, Schema as S } from 'effect'
import { envVars } from '../config.js'

Method Implementation Patterns

HTTP Method Mapping

  • GET requests for data retrieval
  • POST requests for resource creation
  • PUT requests for resource updates
  • DELETE requests for resource deletion
// ✅ CORRECT - HTTP method usage
createDraft: ({ authorId }: { authorId: UserId }) =>
  HttpClientRequest.post('/v1/blog').pipe(
    HttpClientRequest.bodyJson(CreateBlogPostInput.make({ authorId })),
    // ...
  ),

updateAttributes: (blogPostId: string, patches: BlogPostPatches) =>
  HttpClientRequest.put(`/v1/blog/${blogPostId}`).pipe(
    HttpClientRequest.bodyJson(patches),
    // ...
  ),

delete: (id: string) =>
  HttpClientRequest.del(`/v1/blog/${id}`).pipe(
    // ...
  ),

Read the full file on GitHub · 368 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 368 lines · 2,387 tokens per session scan A 835ce53b913c

Subscribe to this mod's changes

api-client-patterns is a cursor rule published in the GitHub repository CharLEE-X/effect-cursor-rules (6 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,387 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.