[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/rest-api/ -> class-wp-rest-server.php (summary)

REST API: WP_REST_Server class

File Size: 1336 lines (38 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_REST_Server:: (26 methods):
  __construct()
  check_authentication()
  error_to_response()
  json_error()
  serve_request()
  response_to_data()
  get_response_links()
  get_compact_response_links()
  embed_links()
  envelope_response()
  register_route()
  get_routes()
  get_namespaces()
  get_route_options()
  dispatch()
  get_json_last_error()
  get_index()
  get_namespace_index()
  get_data_for_routes()
  get_data_for_route()
  set_status()
  send_header()
  send_headers()
  remove_header()
  get_raw_data()
  get_headers()


Class: WP_REST_Server  - X-Ref

Core class used to implement the WordPress REST API server.

__construct()   X-Ref
Instantiates the REST server.

since: 4.4.0

check_authentication()   X-Ref
Checks the authentication headers if supplied.

return: WP_Error|null WP_Error indicates unsuccessful login, null indicates successful
since: 4.4.0

error_to_response( $error )   X-Ref
Converts an error to a response object.

This iterates over all error codes and messages to change it into a flat
array. This enables simpler client behaviour, as it is represented as a
list in JSON rather than an object/map.

return: WP_REST_Response List of associative arrays with code and message keys.
param: WP_Error $error WP_Error instance.
since: 4.4.0

json_error( $code, $message, $status = null )   X-Ref
Retrieves an appropriate error representation in JSON.

Note: This should only be used in WP_REST_Server::serve_request(), as it
cannot handle WP_Error internally. All callbacks and other internal methods
should instead return a WP_Error with the data set to an array that includes
a 'status' key, with the value being the HTTP status to send.

return: string JSON representation of the error
param: string $code    WP_Error-style code.
param: string $message Human-readable message.
param: int    $status  Optional. HTTP status code to send. Default null.
since: 4.4.0

serve_request( $path = null )   X-Ref
Handles serving an API request.

Matches the current server URI to a route and runs the first matching
callback then outputs a JSON representation of the returned value.

return: false|null Null if not served and a HEAD request, false otherwise.
param: string $path Optional. The request route. If not set, `$_SERVER['PATH_INFO']` will be used.
since: 4.4.0

response_to_data( $response, $embed )   X-Ref
Converts a response to data to send.

return: array {
param: WP_REST_Response $response Response object.
param: bool             $embed    Whether links should be embedded.
since: 4.4.0

get_response_links( $response )   X-Ref
Retrieves links from a response.

Extracts the links from a response into a structured hash, suitable for
direct output.

return: array Map of link relation to list of link hashes.
param: WP_REST_Response $response Response to extract links from.
since: 4.4.0

get_compact_response_links( $response )   X-Ref
Retrieves the CURIEs (compact URIs) used for relations.

Extracts the links from a response into a structured hash, suitable for
direct output.

return: array Map of link relation to list of link hashes.
param: WP_REST_Response $response Response to extract links from.
since: 4.5.0

embed_links( $data )   X-Ref
Embeds the links from the data into the request.

return: array {
param: array $data Data from the request.
since: 4.4.0

envelope_response( $response, $embed )   X-Ref
Wraps the response in an envelope.

The enveloping technique is used to work around browser/client
compatibility issues. Essentially, it converts the full HTTP response to
data instead.

return: WP_REST_Response New response with wrapped data
param: WP_REST_Response $response Response object.
param: bool             $embed    Whether links should be embedded.
since: 4.4.0

register_route( $namespace, $route, $route_args, $override = false )   X-Ref
Registers a route to the server.

param: string $namespace  Namespace.
param: string $route      The REST route.
param: array  $route_args Route arguments.
param: bool   $override   Optional. Whether the route should be overridden if it already exists.
since: 4.4.0

get_routes()   X-Ref
Retrieves the route map.

The route map is an associative array with path regexes as the keys. The
value is an indexed array with the callback function/method as the first
item, and a bitmask of HTTP methods as the second item (see the class
constants).

Each route can be mapped to more than one callback by using an array of
the indexed arrays. This allows mapping e.g. GET requests to one callback
and POST requests to another.

Note that the path regexes (array keys) must have @ escaped, as this is
used as the delimiter with preg_match()

return: array `'/path/regex' => array( $callback, $bitmask )` or
since: 4.4.0

get_namespaces()   X-Ref
Retrieves namespaces registered on the server.

return: array List of registered namespaces.
since: 4.4.0

get_route_options( $route )   X-Ref
Retrieves specified options for a route.

return: array|null Data as an associative array if found, or null if not found.
param: string $route Route pattern to fetch options for.
since: 4.4.0

dispatch( $request )   X-Ref
Matches the request to a callback and call it.

return: WP_REST_Response Response returned by the callback.
param: WP_REST_Request $request Request to attempt dispatching.
since: 4.4.0

get_json_last_error()   X-Ref
Returns if an error occurred during most recent JSON encode/decode.

Strings to be translated will be in format like
"Encoding error: Maximum stack depth exceeded".

return: bool|string Boolean false or string error message.
since: 4.4.0

get_index( $request )   X-Ref
Retrieves the site index.

This endpoint describes the capabilities of the site.

return: array Index entity
param: array $request {
since: 4.4.0

get_namespace_index( $request )   X-Ref
Retrieves the index for a namespace.

return: WP_REST_Response|WP_Error WP_REST_Response instance if the index was found,
param: WP_REST_Request $request REST request instance.
since: 4.4.0

get_data_for_routes( $routes, $context = 'view' )   X-Ref
Retrieves the publicly-visible data for routes.

return: array Route data to expose in indexes.
param: array  $routes  Routes to get data for.
param: string $context Optional. Context for data. Accepts 'view' or 'help'. Default 'view'.
since: 4.4.0

get_data_for_route( $route, $callbacks, $context = 'view' )   X-Ref
Retrieves publicly-visible data for the route.

return: array|null Data for the route, or null if no publicly-visible data.
param: string $route     Route to get data for.
param: array  $callbacks Callbacks to convert to data.
param: string $context   Optional. Context for the data. Accepts 'view' or 'help'. Default 'view'.
since: 4.4.0

set_status( $code )   X-Ref
Sends an HTTP status code.

param: int $code HTTP status.
since: 4.4.0

send_header( $key, $value )   X-Ref
Sends an HTTP header.

param: string $key Header key.
param: string $value Header value.
since: 4.4.0

send_headers( $headers )   X-Ref
Sends multiple HTTP headers.

param: array $headers Map of header name to header value.
since: 4.4.0

remove_header( $key )   X-Ref
Removes an HTTP header from the current response.

param: string $key Header key.
since: 4.8.0

get_raw_data()   X-Ref
Retrieves the raw request entity (body).

return: string Raw request data.
since: 4.4.0

get_headers( $server )   X-Ref
Extracts headers from a PHP-style $_SERVER array.

return: array Headers extracted from the input.
param: array $server Associative array similar to `$_SERVER`.
since: 4.4.0



Generated: Sat Sep 21 01:00:03 2019 Cross-referenced by PHPXref 0.7.1