慣性聚合 高效追讀感興趣之博客、新聞、科技資訊
閱原文 以慣性聚合開啟

推薦訂閱源

博客园 - 司徒正美
V
V2EX
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
月光博客
月光博客
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python)
《二零二六年API设计全鉴:REST、GraphQL与tRPC之生产应用》
ZNY · 2026-05-24 · via DEV Community

ZNY

《二零二六年API设计全鉴:REST、GraphQL及tRPC之生产应用》

二零二六年,API设计之格局,渐定三式:REST用于公API与微服务,GraphQL应繁杂数据之需,tRPC适TypeScript全栈之用。

三者皆有其宜,谬误生于众择,非据契合,乃凭喧嚣。

休于二六:本固由是

REST APIs 仍为:

  • 公共与伙伴 API(文牍简易,工具有序)
  • 微服务需简明契约者
  • 无 TypeScript 全栈专长之团队

二六 REST 之要进:

错误应答更善

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Request validation failed",
    "details": [
      {
        "field": "email",
        "code": "INVALID_FORMAT",
        "message": "Must be a valid email address"
      }
    ],
    "requestId": "req_a1b2c3d4e5"
  }
}

入全景模式 出全屏模式

requestId加法之变,令吾辈调试之道焕然一新。今每误皆链于结构化之日志矣。

版本控制

犹为纷争之最。吾辈二零二六之议:唯重大版本破折时,方用URL版本。

GET /v1/users     ← Major version, breaking changes
GET /users?since= ← Minor additions, no versioning

入全景模式 出全屏模式

速率限制之头信息

标准化速率限制之头信息终成惯例:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1716560400
Retry-After: 3600

入全屏模式 出全屏模式

GraphQL:实为适切之选时

GraphQL显其能于:

  1. 复杂、嵌套之数据需求:一仪表盘,取用用户、其订单、订单中之产品及产品供应商之数据。以REST,需四请求以上或过度获取之端点。

  2. :多客户端类型:移动(需异于桌面之数据)与网页客户端,各有异求。GraphQL之灵活查询,处理此事宜。

  3. :客户端速变: 若手机与网页之团队各自为政,则 GraphQL 之架构契约可减协调之劳。

GraphQL非是之时

  • 简易增删改查若汝主要从事于单一资源的创建、读取、更新、删除,则 REST 更为简明,且对此模式有更优之工具。
  • 文件上传: 仍觉 GraphQL 之用为拙,此务宜以 REST 为之。
  • 缓存: 以 HTTP 缓存之 REST,于公可缓之数据,则简而效。

范式之设规

GraphQL之长,在于其类型系统。然此需自律:

type User {
  id: ID!
  email: String!
  createdAt: DateTime!

  # Explicitly define what's included, avoid N+1
  orders(first: Int, after: String): OrderConnection!
  totalOrderCount: Int! # Pre-computed, not derived
}

type OrderConnection {
  edges: [OrderEdge!]!
  pageInfo: PageInfo!
  totalCount: Int!
}

入全景模式 出全屏模式

"其"totalCount 乃为别项(预算)以避每请皆询COUNT(*)之患。

tRPC:泰斯派克思之革命

tRPC于二二五年至二六年间成为泰斯派克思独库之标配。其引以为傲者,乃端至类型安全而无需代码生成。

// Server: define the procedure
const userRouter = router({
  getById: publicProcedure
    .input(z.object({ id: z.string() }))
    .query(async ({ input }) => {
      return db.user.findUnique({ where: { id: input.id } });
    }),
});

// Client: fully typed, no code generation
const user = await trpc.user.getById.query({ id: userId });
// user is typed based on the server definition

入全屏模式 出全屏模式

既用 TypeScript 之众,则其效率之增,实有可睹。然其权衡之计:须立 TypeScript 之独库,且 Zod 之架构,其学之难,亦不容忽.

择 tRPC 之时宜于__JHSNS_SEG_4cbc8364_51__:全栈 TypeScript 之众,速成之务,内用之器,初创之业,急进之途
不宜于多语言环境,公版API,无TypeScript专长之团队

决策之框架

Is your team TypeScript-first with a monorepo?
  → YES → tRPC for internal services, REST for public APIs
  → NO  → Continue below

Do clients need different data shapes for the same endpoint?
  → YES → GraphQL
  → NO  → Continue below

Is this a public/partner API?
  → YES → REST (better tooling, easier to document, broader client support)
  → NO  → REST is probably fine, GraphQL if the data model is complex

入全景模式 出全景模式

2026年要紧之工具

为REST:

  • Zod用于输入验证(替Joi及class-validator)
  • HonoFastify以应乎框架(Express渐显其老态)
  • scalarredocly

以备乎API之文籍

  • 至于GraphQL:GraphQL Yoga 5
  • (已代Apollo Server为常设)联盟首定架构而后施为
  • 画室为探查与监察之用

为 tRPC 而言:

  • TanStack Query(TanStack Query)客也(与tRPC自然相合)
  • 左道以输入之验
  • 询之为类型安全的数据库查询

此文含联盟链接。若尔经此链接注册,吾或得佣金,尔亦无额外之费。

已可营建尔之在线商贾乎?

始用Systeme.io,无费也— 一体化平台,助尔以人工智能之器,营建在线之业。