Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)48k · #3778

api-sdk-generator

Skill này làm gì

Công cụ này tự động tạo code (gọi là SDK) giúp đơn giản hóa việc giao tiếp với API (dịch vụ trực tuyến). Nó tạo các thư viện để chương trình khác dùng dịch vụ này dễ dàng và có tổ chức hơn, xác định cách gửi và nhận dữ liệu.

Khi nào nên dùng

  • ✓Khi bạn cần chương trình giao tiếp với một dịch vụ trực tuyến (API).
  • ✓Khi tạo một ứng dụng mới sẽ dùng dữ liệu từ một API có sẵn.
  • ✓Khi muốn tổ chức và đơn giản hóa việc truy cập API trong code.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/api-sdk-generator/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/api-sdk-generator/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tạo một Python SDK cho API quản lý người dùng, gồm các model yêu cầu/phản hồi và xử lý lỗi.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ phân tích mô tả của API và tạo các file code định nghĩa cách kết nối, gửi lệnh và nhận phản hồi. Nó sắp xếp code này vào các thư mục để dễ sử dụng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

API SDK & Codegen Skill

When to Use

Use this skill when you need generates client SDK code, API wrapper libraries, request/response models, and language-specific usage patterns for any REST API. Use whenever the user asks to "generate an SDK", "write a client library", "create API wrappers", "generate TypeScript types from my API", "write a Python...

Generate production-quality client libraries and SDK code for any API in any language.


SDK Structure (any language)

sdk/
├── client.{ext}          — main client class with base URL, auth, retry
├── resources/
│   ├── users.{ext}       — one file per API resource
│   ├── orders.{ext}
│   └── ...
├── models/
│   ├── user.{ext}        — request/response data models
│   └── ...
├── errors.{ext}          — typed error classes
└── utils/
    ├── retry.{ext}
    └── pagination.{ext}

Base Client Pattern

Python

import httpx
from typing import Optional
import time

class APIClient:
    def __init__(self, api_key: str, base_url: str = "https://api.example.com/v1"):
        self.base_url = base_url
        self._headers = {
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json",
            "User-Agent": "example-sdk-python/1.0.0"
        }
        self._client = httpx.Client(timeout=30.0)

    def _request(self, method: str, path: str, **kwargs) -> dict:
        url = f"{self.base_url}{path}"
        for attempt in range(3):
            try:
                resp = self._client.request(method, url, headers=self._headers, **kwargs)
                if resp.status_code == 429:
                    retry_after = int(resp.headers.get("Retry-After", 2 ** attempt))
                    time.sleep(retry_after)
                    continue
                resp.raise_for_status()
                return resp.json()
            except httpx.HTTPStatusError as e:
                raise APIError(e.response.status_code, e.response.json()) from e
        raise RateLimitError("Max retries exceeded")

TypeScript

class APIClient {
  private readonly baseUrl: string;
  private readonly headers: Record<string, string>;

  constructor(apiKey: string, baseUrl = 'https://api.example.com/v1') {
    this.baseUrl = baseUrl;
    this.headers = {
      'Authorization': `Bearer ${apiKey}`,
      'Content-Type': 'application/json',
    };
  }

  async request<T>(method: string, path: string, body?: unknown): Promise<T> {
    const res = await fetch(`${this.baseUrl}${path}`, {
      method,
      headers: this.headers,
      body: body ? JSON.stringify(body) : undefined,
    });
    if (!res.ok) {
      const err = await res.json();
      throw new APIError(res.status, err.message);
    }
    return res.json() as T;
  }
}

Resource Class Pattern

Python

from dataclasses import dataclass
from typing import Optional, List

@dataclass
class User:
    id: str
    name: str
    email: str
    created_at: str
    role: Optional[str] = None

class UsersResource:
    def __init__(self, client: APIClient):
        self._client = client

    def list(self, page: int = 1, limit: int = 20) -> List[User]:
        data = self._client._request("GET", f"/users?page={page}&limit={limit}")
        return [User(**u) for u in data["data"]]

    def get(self, user_id: str) -> User:
        data = self._client._request("GET", f"/users/{user_id}")
        return User(**data)

    def create(self, name: str, email: str, role: Optional[str] = None) -> User:
        payload = {"name": name, "email": email}
        if role:
            payload["role"] = role
        data = self._client._request("POST", "/users", json=payload)
        return User(**data)

    def delete(self, user_id: str) -> None:
        self._client._request("DELETE", f"/users/{user_id}")

Typed Error Classes

class APIError(Exception):
    def __init__(self, status_code: int, message: str):
        self.status_code = status_code
        self.message = message
        super().__init__(f"HTTP {status_code}: {message}")

class AuthenticationError(APIError): pass   # 401
class AuthorizationError(APIError): pass    # 403
class NotFoundError(APIError): pass         # 404
class ValidationError(APIError): pass       # 422
class RateLimitError(APIError): pass        # 429
class ServerError(APIError): pass           # 5xx

Pagination Helper

def paginate(resource_method, **kwargs):

…
Câu hỏi thường gặp

SDK là gì?

SDK là viết tắt của “Software Development Kit” (bộ công cụ phát triển phần mềm). Đó là tập hợp công cụ và code giúp lập trình viên xây dựng ứng dụng tương tác với một dịch vụ cụ thể, như API.

API là gì?

API là viết tắt của “Application Programming Interface” (giao diện lập trình ứng dụng). Đó là tập hợp các quy tắc và định nghĩa cho phép các chương trình phần mềm khác nhau giao tiếp với nhau.

Tại sao nên dùng SDK được tạo tự động?

Nó tiết kiệm thời gian và đảm bảo việc giao tiếp với API được thực hiện theo cách chuẩn hóa và đúng, theo các thực hành lập trình tốt nhất.

Chi tiết

Mô tả gốc của tác giả

Generates client SDK code, API wrapper libraries, request/response models, and language-specific usage patterns for any REST API.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#3778
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự