Property | Type | Description | |
---|---|---|---|
$endpoints | array | Endpoints registered to the server. | |
$namespaces | array | Namespaces registered to the server. | |
$route_options | array | Options defined for the routes. |
Method | Description | |
---|---|---|
__construct ( ) | Instantiates the REST server. | |
check_authentication ( ) : WP_Error | null | Checks the authentication headers if supplied. | |
dispatch ( WP_REST_Request $request ) : WP_REST_Response | Matches the request to a callback and call it. | |
envelope_response ( WP_REST_Response $response, boolean $embed ) : WP_REST_Response | Wraps the response in an envelope. | |
get_compact_response_links ( WP_REST_Response $response ) : array | Retrieves the CURIEs (compact URIs) used for relations. | |
get_data_for_route ( string $route, array $callbacks, string $context = 'view' ) : array | null | Retrieves publicly-visible data for the route. | |
get_data_for_routes ( array $routes, string $context = 'view' ) : array | Retrieves the publicly-visible data for routes. | |
get_headers ( array $server ) : array | Extracts headers from a PHP-style $_SERVER array. | |
get_index ( array $request ) : array | Retrieves the site index. | |
get_namespace_index ( WP_REST_Request $request ) : WP_REST_Response | WP_Error | Retrieves the index for a namespace. | |
get_namespaces ( ) : array | Retrieves namespaces registered on the server. | |
get_raw_data ( ) : string | Retrieves the raw request entity (body). | |
get_response_links ( WP_REST_Response $response ) : array | Retrieves links from a response. | |
get_route_options ( string $route ) : array | null | Retrieves specified options for a route. | |
get_routes ( ) : array | Retrieves the route map. | |
register_route ( string $namespace, string $route, array $route_args, boolean $override = false ) | Registers a route to the server. | |
response_to_data ( WP_REST_Response $response, boolean $embed ) : array | Converts a response to data to send. | |
send_header ( string $key, string $value ) | Sends an HTTP header. | |
send_headers ( array $headers ) | Sends multiple HTTP headers. | |
serve_request ( string $path = null ) : false | null | Handles serving an API request. |
Method | Description | |
---|---|---|
embed_links ( array $data ) : array | Embeds the links from the data into the request. | |
error_to_response ( WP_Error $error ) : WP_REST_Response | Converts an error to a response object. | |
get_json_last_error ( ) : boolean | string | Returns if an error occurred during most recent JSON encode/decode. | |
json_error ( string $code, string $message, integer $status = null ) : string | Retrieves an appropriate error representation in JSON. | |
set_status ( integer $code ) | Sends an HTTP status code. |
public check_authentication ( ) : WP_Error | null | ||
return | WP_Error | null | WP_Error indicates unsuccessful login, null indicates successful or no authentication provided |
public dispatch ( WP_REST_Request $request ) : WP_REST_Response | ||
$request | WP_REST_Request | Request to attempt dispatching. |
return | WP_REST_Response | Response returned by the callback. |
protected embed_links ( array $data ) : array | ||
$data | array | Data from the request. |
return | array | { Data with sub-requests embedded. @type array [$_links] Links. @type array [$_embedded] Embeddeds. } |
public envelope_response ( WP_REST_Response $response, boolean $embed ) : WP_REST_Response | ||
$response | WP_REST_Response | Response object. |
$embed | boolean | Whether links should be embedded. |
return | WP_REST_Response | New response with wrapped data |
protected error_to_response ( WP_Error $error ) : WP_REST_Response | ||
$error | WP_Error | WP_Error instance. |
return | WP_REST_Response | List of associative arrays with code and message keys. |
public static get_compact_response_links ( WP_REST_Response $response ) : array | ||
$response | WP_REST_Response | Response to extract links from. |
return | array | Map of link relation to list of link hashes. |
public get_data_for_route ( string $route, array $callbacks, string $context = 'view' ) : array | null | ||
$route | string | Route to get data for. |
$callbacks | array | Callbacks to convert to data. |
$context | string | Optional. Context for the data. Accepts 'view' or 'help'. Default 'view'. |
return | array | null | Data for the route, or null if no publicly-visible data. |
public get_headers ( array $server ) : array | ||
$server | array | Associative array similar to `$_SERVER`. |
return | array | Headers extracted from the input. |
protected get_json_last_error ( ) : boolean | string | ||
return | boolean | string | Boolean false or string error message. |
public get_namespace_index ( WP_REST_Request $request ) : WP_REST_Response | WP_Error | ||
$request | WP_REST_Request | REST request instance. |
return | WP_REST_Response | WP_Error | WP_REST_Response instance if the index was found, WP_Error if the namespace isn't set. |
public get_namespaces ( ) : array | ||
return | array | List of registered namespaces. |
public static get_raw_data ( ) : string | ||
return | string | Raw request data. |
public static get_response_links ( WP_REST_Response $response ) : array | ||
$response | WP_REST_Response | Response to extract links from. |
return | array | Map of link relation to list of link hashes. |
public get_routes ( ) : array | ||
return | array | `'/path/regex' => array( $callback, $bitmask )` or `'/path/regex' => array( array( $callback, $bitmask ), ...)`. |
public register_route ( string $namespace, string $route, array $route_args, boolean $override = false ) | ||
$namespace | string | Namespace. |
$route | string | The REST route. |
$route_args | array | Route arguments. |
$override | boolean | Optional. Whether the route should be overridden if it already exists. Default false. |
public response_to_data ( WP_REST_Response $response, boolean $embed ) : array | ||
$response | WP_REST_Response | Response object. |
$embed | boolean | Whether links should be embedded. |
return | array | { Data with sub-requests embedded. @type array [$_links] Links. @type array [$_embedded] Embeddeds. } |
public send_header ( string $key, string $value ) | ||
$key | string | Header key. |
$value | string | Header value. |
public send_headers ( array $headers ) | ||
$headers | array | Map of header name to header value. |
public serve_request ( string $path = null ) : false | null | ||
$path | string | Optional. The request route. If not set, `$_SERVER['PATH_INFO']` will be used. Default null. |
return | false | null | Null if not served and a HEAD request, false otherwise. |
protected set_status ( integer $code ) | ||
$code | integer | HTTP status. |
protected array $endpoints | ||
return | array |
protected array $namespaces | ||
return | array |
protected array $route_options | ||
return | array |