- 
                Notifications
    You must be signed in to change notification settings 
- Fork 7
Core Documentation
Incomplete
Controllers serve two functions.
- To provide endpoints.
- To route to other controllers.
Endpoints are the bread an butter of an api, they provide the functionality. In Aye Aye, endpoints are specially named
methods inside controllers. The naming convention works like this [verb][Name]Endpoint.
- The [verb]is an HTTP verb or method. For examplegetandpostare valid verbs. These are written in lower case.
- The [Name]is the name of your endpoint as it will appear in the url. The is must start with a capital letter and if the endpoint is multiple words that you'd like to separate, then each new word should be capitalised.
- The word Endpointis added to the end to tell Aye Aye that this is an endpoint, and not some other type of method, you do not want visible and accessible to the outside world.
Endpoint methods should return the data you want the user to receive.
Example
public function getHelloWorldEndpoint(...) {
   ...
}In the example above, we have created an endpoint called HelloWorld. It uses the get verb, so you can access it by
sending a get request to /hello-world. Notice the casing of the name caused the url to break into a readable
Aye Aye uses a single controller as a starting point, all other controllers must be accessible via that controller. We
do this by adding methods that using the following naming convention [name]Controller.
- The [name]is the name of your controller as it will appear in the url. The is must start with a capital letter and if the endpoint is multiple words that you'd like to separate, then each new word should be capitalised.
- The word Controlleris added to the end to tell Aye Aye that this method provides access to another controller. It will be listed separately from the current controllers endpoints.
Controller methods must return an instance of another controller.
Example
public function fooBarController() {
    returns new FooBar();
}This example will allow access to the FooBar Controllers endpoints and sub controllers via the url /foo-bar.
Aye Aye includes a special Exception designed to provide more useful information to your end users. Simply, they
can be given two messages, one for you which should be logged, and one to send the user. Furthermore, the exceptions
code will be carried forward as an HTTP status. Here's the constructor:
public function __construct($publicMessage = '', $code = 500, $systemMessage = '', \Exception $previous = null)The important thing to note here is that the first message is now public. This message can be used to inform the user of what went wrong. The code defaults to 500, which will be translated to an Internal Server Error.
Example
// use \AyeAye\Api\Exception;
public function getExceptionEndpoint() {
    throw new Exception(
        'Hello Exception',    // Data returned to user
        500,                  // The HTTP status code
        'User hit Exception', // Message for your logs
        null                  // Any exception can be added here
    );
}