Skip to main content
Version: 9.x


The basic flow#

When an HTTP request is received, it first hits your predefined Endpoint (each endpoint live in its own Route file).

Sample Route Endpoint#

<?php$router->get('hello', [    'uses' => '[email protected]',]);

After the user makes a request to the endpoint [GET] it calls the defined controller function (sayHello).

Sample Controller Function#

<?phpclass Controller extends ApiController{    public function sayHello(SayHelloRequest $request)    {            $helloMessage = Apiato::call(SayHelloAction::class);
            $this->json([                $helloMessage            ]);    }}

This function takes a Request class SayHelloRequest to automatically checks if the user has the right access to this endpoint. Only if the user has access, it proceeds to the function body.

Then the function calls an Action (SayHelloAction) to perform the business logic.

Sample Action#

<?phpclass SayHelloAction extends Action{    public function run()    {        return 'Hello World!';    }}

The Action can do anything then return a result (could be an Object, a String or anything).

When the Action finishes its job, the controller function gets ready to build a response.

Json responses can be built using the helper function json ($this->json(['foo' => 'bar']);).

Sample User Response#

[    "Hello World!"]