TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Whats your favorite book on API design?

2 pointsby escotover 1 year ago

1 comment

illuminantover 1 year ago
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 未加载