Closed zagarskas closed 1 month ago
Hi @zagarskas, sorry about the loss of life here.
That FontAwesome::query()
function is definitely documented. But yeah, that link from the README is broken. Lame.
Seems like the document generator changed the path for that link at some point.
The best place to get into the PHP API docs is from the README here:
That links to the top-level of the generated PHP API docs here.
From there, those docs are navigable. So you could drill down to the FontAwesome::query()
method here.
I fixed that link from the README as well.
The FontAwesome_API_Controller docs indicate how to POST
a request to that route, but they don't indicate the content-type
header expected. It expects just the default content-type, which according to MDN is: content-type: text/plain
.
(But that's admittedly been implicit, and--to your point--it should be documented, thus saving life.)
(Side note: I've realized that the OWASP security rules used in mod_security
for some Web Application Firewalls, doesn't like to see text/plain
used for POST
requests on this route. So I'm planning to change that in a future release. I think I can keep it backward compatible.)
That "public" query()
function you found in class-fontawesome-api-controller.php
is not really public 😄
The doc comments on that function say:
Internal use only. This method is not part of this plugin's public API.
It's intentionally excluded from the API docs for that reason.
The public PHP API for query through this plugin is either:
FontAwesome::query()
function for which you hit that 404 page. I think its docs probably give you what you need./wp-json/font-awesome/v1/api
REST API route (See the FontAwesome_API_Controller doc for that.)What I infer from your original post is that you read the GraphQL API docs on fontawesome.com and saw the requirement to use content-type: application/json
for that service. Then you tried to use content-type: application/json
when sending a request to the plugin's REST API end, and it didn't work. Is that right?
If so, that's an understandable confusion.
The header content-type: application/json
should indeed be used for any requests to the Font Awesome GraphQL API service at api.fontawesome.com
.
And this WordPress plugin, on the back end, does issue queries to that api.fontawesome.com endpoint using application/json
.
However, if you want to send a POST
request to the WordPress REST API route on your own WordPress server at /wp-json/font-awesome/v1/api
, then that end point does not expect application/json
.
It expects a plain text GraphQL query document as a body of the POST request, not a JSON document. That's documented in the FontAwesome_API_Controller docs.
If you send a POST request to that WordPress REST API endpoint with content-type: application/json
it won't work, which seems like what you discovered.
FontAwesome::query()
is fixedPOST
request to the /wp-json/font-awesome/v1/api
route with a content-type: text/plain
and a plain text GraphQL query as the body.query()
method is not available as part of the public api
This link on this page is 404![image](https://github.com/FortAwesome/wordpress-fontawesome/assets/859427/509c6771-34d9-4d69-990f-6a73bacb6859)
https://fortawesome.github.io/wordpress-fontawesome/classes/FortAwesome.FontAwesome.html#method_query
Searching google for
FontAwesome::query()
brings no love.Also note, the documentation on the following pages may not be accurate (or PHP8.2 and WPengine may be at fault here)
Content-Type: application/json
does not workThe following would have been super helpful to know.
I was able to find
public function query( $request )
withinclass-fontawesome-api-controller.php
which is what lead me to believe I should be usingWP_REST_Request
becauseclass FontAwesome_API_Controller extends WP_REST_Controller
In closing:
FontAwesome::query()
documentation would be goodPS: the WP plugin is super cool in all other regards. I have now read through most of the code, its nicely done.