REST API Hooks

See …/developer/rest-api.md for endpoint behavior. This page focuses only on PHP action and filter hooks exposed by Alpaca’s REST response helpers.

Shared Response Hook

alpaca_rest_response

Type: Action.

Purpose: Fires for every response created through alpaca_rest_response(), regardless of whether the result is successful or an error.

Parameters

Parameter Type Description
$action_type string The response action identifier used to build dynamic hook names.
$data mixed The response payload.
$status int The HTTP status code.

Source: includes/api/utilities/helpers.php:26.

alpaca_rest_{$action_type}

Type: Action.

Purpose: Fires for successful REST responses created through alpaca_rest_response() when the HTTP status code is in the 2xx range.

Parameters

Parameter Type Description
$data mixed The response payload.
$status int The HTTP status code.

Source: includes/api/utilities/helpers.php:30.

Notes: The final action name depends on the $action_type string passed into alpaca_rest_response(). For example, an action type of submit produces alpaca_rest_submit.

alpaca_rest_error_{$action_type}

Type: Action.

Purpose: Fires for non-2xx REST responses created through alpaca_rest_response().

Parameters

Parameter Type Description
$data mixed The error payload.
$status int The HTTP status code.

Source: includes/api/utilities/helpers.php:32.

Notes: The final action name depends on the $action_type string passed into alpaca_rest_response(). For example, an action type of submit can produce alpaca_rest_error_submit for an error response.

Response Object Filter

alpaca_rest_response_object

Type: Filter.

Purpose: Replaces or adjusts the final WP_REST_Response object after Alpaca has created it.

Parameters

Parameter Type Description
$response WP_REST_Response The response object Alpaca is about to return.
$action_type string The response action identifier.
$data mixed The response payload.
$status int The HTTP status code.

Source: includes/api/utilities/helpers.php:38-44.

REST Root Resolution

alpaca_rest_api_root

Type: Filter.

Purpose: Overrides the REST API root URL Alpaca injects into localized front-end settings.

Parameters

Parameter Type Description
$default_root string The default REST root generated by rest_url(). This value is passed as the first filter argument and can be replaced.
$context array Context with default_root and parsed request origin data.

Source: includes/api/utilities/rest-root.php:103-110.