Request to response
Make one PHP endpoint easier to reason about from the first input to the final response.
Write down the input contract
List the accepted request method, field names, types, and limits next to the handler. Decide how an empty value differs from an omitted value. Normalize values once, then pass the resulting data to the operation as named inputs. Add a test for any existing client that reliably depends on unusual input.
Give each outcome a visible shape
Describe what a caller receives for success, an invalid field, and an unexpected failure. Keep the public error specific enough for a caller to fix their request. Write the details needed for diagnosis to an internal log. If the response includes user text, apply escaping appropriate to its context when rendering it.
- Test a valid request and its status and body.
- Test missing and malformed inputs separately.
- Verify an unexpected failure produces a useful internal log entry.