The shop stops selling the Gift card. To remove a product, a client sends a DELETE to the product's own path, /products/8: the third method on that path, after GET and PUT. It needs no body: the id in the path says it all.
Here is a DELETE on another table, a list of newsletter subscribers:
res, _ := db.Exec("DELETE FROM subscribers WHERE id = ?", 3)
changed, _ := res.RowsAffected()
fmt.Println(changed) // 1 if subscriber 3 was there, 0 if not
The WHERE matters even more than in an UPDATE: DELETE FROM products alone empties the whole table. Deleting an id that isn't there is no error, it just removes nothing, so res.RowsAffected() is 0 and you answer 404. When a product is removed, you answer 204 No Content with an empty body: it worked, and there is nothing to send back.
Starting from the shop's 8 products, your code must answer, in this order:
DELETE /products/8 → 204 (empty body)
GET /products/8 → 404 {"error": "Product not found"}
DELETE /products/8 → 404 {"error": "Product not found"}
DELETE /products/99 → 404 {"error": "Product not found"}
Your task: add the handler DELETE /products/{id}. Delete that product with a ? placeholder. Answer 404 if no row was removed, and otherwise an empty body with the status 204.
Assignment
Follow the Coding Tutorial to add the DELETE /products/{id} handler, which removes a product from the database.
Hint
A DELETE gives back no rows, so run it with db.Exec and pass id after the SQL, for the ?. For the 204, w.WriteHeader(204) sends just the status: write nothing after it.
Free plan: 30 tutor messages. PRO is unlimited.
