PHP is more than capable of powering clean, RESTful APIs without any heavy frameworks. By understanding the HTTP methods and properly structuring your code, you can deliver JSON responses your front-end will love.
1. Inspect the request
Determine the endpoint and HTTP method using $_SERVER['REQUEST_METHOD'] and parse $_SERVER['REQUEST_URI'] to choose the appropriate handler.
2. Structure controllers
Create functions or classes that encapsulate your business logic. Keep your routing thin and your controllers reusable. Return arrays that you can later encode as JSON.
3. Send proper responses
Always set the correct Content-Type header and status codes. Use http_response_code() to signal success or failure and provide meaningful error messages in the body.