On his Medium blog Peter Lafferty has written up a post showing you a method for HTTP request validation in Silex, the microframework from the creators of Symfony.
This article covers three validation scenarios: routes, query strings [and] POST with a JSON body.
He starts with a simple Silex application that creates a "RESTful" API with endpoints providing emojis back when queried (three endpoints). He then uses this to show how to validate:
- routes for their expected values in the URL
- using a ValidatorService provider to build a set of assertions (GET request)
- using the same service to create assertions for the JSON content of a POST request
All code required is included in the post including the correct handling of the emoji output via a UTF-8 JSON response handler.