TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Whats your favorite book on API design?

2 点作者 escot超过 1 年前

1 comment

illuminant超过 1 年前
Will save you some trouble reading a book. Wisdoms I&#x27;ve learned over the years...<p>- single entry point (&#x2F;api&#x2F;) which delegates dynamically to named resources in a components (or &quot;plugin&quot;) folder. (So &#x2F;api&#x2F;user&#x2F;... Is delegated to (app&#x2F;plugins&#x2F;user.ext) which may subroute.<p>- Do not follow full CRUD. Instead only support GET and POST. Use POST to upsert. If no GUID (0), it&#x27;s new. Delete is a flag (never actually remove records, instead set a delete flag and use that in queries.) (Note: not universally popular yet practical)<p>- Use ULIDs or UUIDv7+ (serialized, timecoded, good entropy.) If you want to be hard core (best index performance), save in db as binary and convert to conventional format for front end usage.<p>- do not return a raw data set result, instead return an envelope containing the data set { status, message, data }. Set proper HTTP response headers.<p>- generate a single use session token on authorization (set in the HTTP request header), use that to track sessions.<p>- dont use redundant names (&#x2F;api&#x2F;user&#x2F;user_profile) just use &#x2F;api&#x2F;user&#x2F;profile. Seems obvious and yet ...<p>Hope you find this helpful! Let me know if I haven&#x27;t addressed something (or to argue about that CRUD COMMENT ;)
评论 #39006016 未加载