A simple PHP REST API application with 3 endpoints, containerized with Docker.
- GET
/api/health - Returns server health status and information
- GET
/api/users- Get all users - POST
/api/users- Create a new user- Body:
{ "name": "John Doe", "email": "john@example.com" }
- Body:
- GET
/api/products- Get all products - GET
/api/products?id=1- Get a specific product by ID - POST
/api/products- Create a new product- Body:
{ "name": "Product Name", "price": 99.99, "stock": 50 }
- Body:
docker build --platform=linux/amd64 -t php-rest-api .docker run -d -p 8000:8000 --name php-api php-rest-api# Health check
curl http://localhost:8000/api/health
# Get all users
curl http://localhost:8000/api/users
# Create a user
curl -X POST http://localhost:8000/api/users \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"john@example.com"}'
# Get all products
curl http://localhost:8000/api/products
# Get specific product
curl http://localhost:8000/api/products?id=1
# Create a product
curl -X POST http://localhost:8000/api/products \
-H "Content-Type: application/json" \
-d '{"name":"Laptop","price":999.99,"stock":50}'php -S localhost:8000Then access the API at http://localhost:8000
The Alpine-based image is lightweight (~50MB) and optimized for production use.