WP-API / docs

The content for developer.wordpress.org/rest-api
https://developer.wordpress.org/rest-api
110 stars 615 forks source link

Fix request method for REST API discovery #123

Closed SkypLabs closed 2 years ago

SkypLabs commented 2 years ago

As explained on the "Reference" page, the REST API discovery process is made available through OPTIONS requests, not HEAD unlike what said on the "Discovery" page.

This PR fixes this mistake.

SkypLabs commented 2 years ago

Actually, both methods return the Link HTTP header so it's not a mistake but an inconsistency.

Would you prefer specifying in the documentation that both methods work, or sticking to only one of them to keep the documentation consistent?

TimothyBJacobs commented 2 years ago

Hi @SkypLabs,

Yeah this intentionally is a HEAD request not an OPTIONS request. Any HTTP method will work, WordPress Core adds the header to all responses. So I don't think we need to call out the OPTIONS request method specifically.

SkypLabs commented 2 years ago

Hi @TimothyBJacobs,

Don't you think the documentation could be improved to specify somewhere that both HEAD and OPTIONS return the Link HTTP header? As someone new to WordPress development, it was confusing to me to read on one page that I need to use a HEAD request, and then on another page that I need to use an OPTIONS request instead.

TimothyBJacobs commented 2 years ago

No I don't think so because the methods are different. A HEAD request returns only the response headers for the endpoint. An OPTIONS request returns information about what data the endpoint accepts and returns via the argument information and schema information.

When you are doing the discovery process, you only need to do a HEAD request if you don't have need for the additional data that an OPTIONS request provides and a HEAD request is in fact preferable.

SkypLabs commented 2 years ago

That makes sense. Thanks for the clarification.