A minimal Go HTTP server that exposes a small in-memory products API. It ships with a few seeded products, supports creating new ones, and can fetch products by ID.
- Go 1.22+
- Standard library only
go run main.goThe server starts on http://localhost:8081.
GET /test
curl http://localhost:8081/testGET /products
Returns the current in-memory product list as JSON.
curl http://localhost:8081/productsGET /products/{id}
curl http://localhost:8081/products/1POST /products
Request body (JSON):
{
"title": "Product name",
"description": "Short description",
"price": 19.99,
"image_url": "https://example.com/image.jpg"
}curl -X POST http://localhost:8081/products \
-H "Content-Type: application/json" \
-d '{"title":"Product name","description":"Short description","price":19.99,"image_url":"https://example.com/image.jpg"}'Notes:
- The server assigns the
idfield automatically. - Data is stored in memory, so restarting the server resets the product list.
- Make sure the
Content-Typeheader isapplication/json.