I have a page that validates data sent via HTTP POST ( http://example.com/http_post ). If the data is good, I add to the database and want to set the HTTP response code 201 and a success message as an HTTP response. If not, I am collecting errors in the array and want to set the HTTP response code and message as a serialized JSON array as an HTTP response.
1) What is the syntax for serializing an error array as JSON in php?
Example
{ "message": "The request is invalid.", "modelState": { "JobType": [ "Please provide a valid job type eg. Perm"] } }
Which syntax sets and returns an HTTP response to 412.
What is the syntax for setting and returning serialized JSON to the body of an HTTP response, as described above.
An example will be useful when setting up all of these HTTP response headers.
thanks
adam78
source share