API Design Examples (CRUD) 00:00:01 Create one product A merchant changes a price on her laptop while a colleague edits the same product on a tablet. Their requests look ordinary. The product API has to decide whether the later arrival is entitled to erase the earlier edit. Name, price, description and stock. The dashboard sends the data as JSON with a token. Permission first, then required fields, types and business rules. The database confirms the new row. The response holds the product and its address. The dashboard shows it with a link to edit. The product is live in the catalogue. Validate the representation before exposing a product identity. Returning where the new resource can be found gives every later read or update an unambiguous target. 00:00:47 Read a limited catalogue A customer browses electronics. The API looks in the cache first. The customer wants to see electronics. Was this page fetched recently? Not there. The database must answer. The rows come back. The page is cached for five minutes. Pictures and prices appear. Page boundaries and a stable sort keep a small catalogue response usable as the store grows. An empty page is a valid result, not automatically an error. 00:01:16 Change one field Staff types 129.99. Only the changed field travels: price 129.99. May this person change prices? Is it a positive number? The database confirms that one row changed. Zero rows would mean 404. The updated product comes back. The dashboard shows a message and the new price. A partial update names which field changes and which values remain. Concurrency is a separate issue even if the request body is only a price. 00:01:48 Remove a product Staff clicks delete on the product. Staff confirms. The request carries the staff token. Remove the row, or mark it as deleted. The database reports one row. The card disappears and a message appears. Define what a repeat deletion returns and what the buyer can observe afterward. A hidden listing, a tombstone and a physically erased record have different implications. 00:02:13 Reject a stale editor Two editors, one product, and a version that stops the second one. Asha and Lee load the product: stock 50, version 7. Asha saves stock 40 with If-Match 7. The versions agree. Lee saves 45 with If-Match 7, but the server is at 8. Nothing is written. Lee reads 40 at version 8, takes off 5 and saves 35. Compare the supplied version with the current one at the write itself. When the versions differ, let the caller inspect and resolve the newer state instead of silently overwriting it. 00:02:47 The creation response disappears The product was created, but the answer never arrived. The dashboard creates a product. The row exists. The 201 is lost on the way back. The dashboard sends it again and now there are two speakers in the catalogue. With the same idempotency key the server returns the first result again. Recover a prior result only for the same operation and equivalent arguments. A reused key with different product details is a conflict to report, not an invitation to return somebody else's creation. A method, a precondition and an operation identifier answer different questions. Together they let a caller distinguish a new change, a stale change and a repeat of one that already worked.