Class Vegas\Http\Response\Json provides a simply JSON response builder, that might be useful to
standardize responses returned by your application's controllers.
Example use:
//...
/**
* Success response
*/
public function createAction()
{
$response = new Json();
$response->success()
->setData(array('test' => 1))
->setMessage('Test message');
return $this->jsonResponse($response);
}
/**
* Errors response
*/
public function createAction()
{
$response = new Json();
$response->fail()
->setData(array())
->setMessage('Errors...');
return $this->jsonResponse($response);
}
//...
{
"success" : true,
"data": {
"test" : 1
},
"message" : "Test message"
}
{
"success" : false,
"data": {},
"message" : "Errors..."
}