Documentation

FontAwesome_API_Controller extends WP_REST_Controller
in package

Controller class for the plugin's GraphQL API REST endpoint.

This controller provides a REST route for WordPress client access to the Font Awesome GraphQL API. It delegates to FontAwesome::query(). The plugin's setting page is a React app that acts as such a client, querying kits.

Requests to this REST route should have the following headers and body:

Headers

  • X-WP-Nonce: include an appropriate nonce from WordPress.
  • Content-Type: application/json

Body

The request body must contain JSON with a GraphQL query document on the "query" property. For example, the following query would return all available Font Awesome version numbers:

{ "query": "query { releases { version } }" }

It may also contain a "variables" property whose value is an object with variable assignments. For example, the following returns all icon identifiers for the latest version of Font Awesome 6.

{
  "query": "query Icons($ver: String!) { release(version:$ver) { icons { id } } }",
  "variables": { "ver": "6.x" }
}

For compatibility with prior versions, this API end point still also allows for sending the request with a plain text body of the query document only, with an implied content-type: text/plain header (the default). However, this format is penalized by the OWASP core ruleset used by mod_security, so it should not be used.

Internal Use vs. Public API

The PHP methods in this controller class are not part of this plugin's public API, but the REST route it exposes is.

If you need to issue a query from server-side PHP code to the Font Awesome API server, use the FontAwesome::query() method.

If you need to issue a query from client-side JavaScript, send an HTTP POST request to WP REST route /font-awesome/v1/api.

Table of Contents

Methods

get_query_body()  : mixed

Methods


        
On this page

Search results