Class AbstractApiV2Controller
This class defines the inner core functionality of a ApiV2Controller. It contains the initialization and request validation functionality that every controller must have.
The functionality of this class is mark as private because child controllers must not alter the state at this point but rather adjust to it. This will force them to follow the same principles and methodologies.
Child API controllers can use the "init" method to initialize their common dependencies.
category |
System |
---|---|
package |
ApiV2Controllers |
__construct(\Slim\Slim $api, array $uri)
Call this constructor from every child controller class in order to set the Slim instance and the request routes arguments to the class.
deprecated |
The "__initialize" method will is deprecated and will be removed in a future version. Please use the new "init" for bootstrapping your child API controllers. |
---|---|
Throws |
|
\Slim\Slim
Slim framework instance, used for request/response manipulation.
array
This array contains all the segments of the current request, starting from the resource.
_prepareResponse()
This method will prepare default attributes of the API responses. Further response settings must be set explicitly from each controller method separately.
Not available to child-controllers (private method).
_setRateLimitHeader()
There is a cache file that will store each user session and provide a security mechanism that will protect the shop from DOS attacks or service overuse. Each session will use the hashed "Authorization header" to identify the client. When the limit is reached a "HTTP/1.1 429 Too Many Requests" will be returned.
Headers: X-Rate-Limit-Limit >> Max number of requests allowed. X-Rate-Limit-Remaining >> Number of requests remaining. X-Rate-Limit-Reset >> UTC epoch seconds until the limit is reset.
Important: This method will be executed in every API call and it might slow the response time due to filesystem operations. If the difference is significant then it should be optimized.
Not available to child-controllers (private method).
Throws |
|
---|
_validateRequest()
This method will validate the request headers, user authentication and other parameters before the controller proceeds with the response.
Not available to child-controllers (private method).
Throws |
|
---|
DEFAULT_PAGE_ITEMS
var |
---|
DEFAULT_CONTROLLER_NAME
var |
---|
DEFAULT_RATE_LIMIT
var |
---|
DEFAULT_RATE_RESET_PERIOD
var |
---|
api : \Slim\Slim
var |
---|
\Slim\Slim
uri : array
Example: URI - api.php/v2/customers/73/addresses CODE - $this->uri[1]; // will return '73'
var |
---|
array