Skip to content

Output REST Web Services

Josh 'VaMoose' harington edited this page Dec 1, 2016 · 2 revisions

Output REST Web Services

The setup

The base route it /_eon_phpstencil/api/rest.

To create your own routes, place them in the routes_rest.php file under the src/Factories/WebService/Routes/ directory.

Create your controller in the src/Factories/WebService/REST/Controllers and extend the RestBaseController class.

Extending this class will give you access to two methods:

  1. return_success
  2. return_error

return_success

The return_success method has two parameters. $messages and $more_data. The second parameter is optional. You can pass through any success messages you like for the $messages parameter, and then any data you wish to present alongside the response with the $more_data parameter.

Note: Both $messages and $more_data are arrays.

return_error

The return_error method only accepts one parameter. $messeges is an array that will hold all error messages in your response.

Returning content to the user

To return content to the user (from the controller), you need to wrap the return_success and return_error methods in a json response. Like this:


return response()->json($this->return_error(['Item does not exist.'])); // request error
return response()->json($this->return_success(['Item deleted.'])); // request successful

Clone this wiki locally