Page MenuHomePhabricator

Update descriptions of title parameter across API docs
Closed, ResolvedPublic

Description

Several Wikimedia API endpoints use a page title as a path parameter. The purpose of this task is to decide on an accurate description for title parameters and update the docs for any applicable APIs.

Problem statement

It would be ideal to be able to document the title parameter as simply "Page title". However, this may lead to confusion if an API users tries to use a title in the wrong format. For example:

  • Some special characters don't work unless encoded:
  • Titles with spaces don't work with curl:
    • example: curl "https://en.wikipedia.org/w/rest.php/v1/page/North America"

Consideration 1: Correct format

It seems that the most correct format for titles in API path parameters is one in which, first, spaces are replaced with underscores, and then the result is URL-encoded. Example: Man%27s_best_friend (https://en.wikipedia.org/w/rest.php/v1/page/Man%27s_best_friend) This is the format returned by the MediaWiki REST API when providing an API URL (see html_url in this response).

Consideration 2: API sandbox behavior

However, the format described above does not work in the API sandbox since swagger UI automatically encodes path parameters:

  • Putting Man%27s_best_friend into the sandbox, results in a request for Man%2527s_best_friend, which 404s
  • Putting Man's best friend into the sandbox, results in a request for Man%27s%20best%20friend, which results in a redirect when using curl

Since the documentation will be read primarily in the context of the sandbox, we should call this out.

Proposed description

"Page title. To format the title, replace spaces with underscores, and then URL-encode the result (example: Steller%27s_jay). In the API sandbox, replace spaces with underscores, but do not URL-encode (example: Steller's_jay)."

Note: I had originally hoped to use "API explorer" instead of "API sandbox", but I found the term "sandbox" has already been well established in the context of Special:RESTSandbox, and that it would be more confusing to try and introduce a different term at this point.

Potential future opportunities for improvement

(Out of scope for this task)

  • API responses could consistently contain page titles in a format suitable for use with the API. For example, the MediaWiki REST API Search pages endpoint returns page titles only in key (Fate/stay_night) and title (Fate/stay night) formats.
  • The API could accept any format for page titles
  • The API could accept page IDs instead of titles
  • The API sandbox could behave the same way as the API

Event Timeline

Just noting that this affects: T419425: Update Attribution API spec generation to improve content style and quality

I updated the ticket with this recommended description. I assume that we will change the root referenced value, so that the change percolates across REST APIs registered through MediaWiki. Also calling out that the Wikimedia REST API documentation will require a separate manual page, since they are statically stored specs.

Thanks, @HCoplin-WMF! I updated T419425 with the latest proposed description from this task that includes examples and will start on a change to the root referenced values shortly.

Change #1256466 had a related patch set uploaded (by Alex Paskulin; author: Alex Paskulin):

[mediawiki/core@master] docs: Clarify format of page title request parameters

https://gerrit.wikimedia.org/r/1256466

Change #1256466 merged by jenkins-bot:

[mediawiki/core@master] docs: Clarify format of page title request parameters

https://gerrit.wikimedia.org/r/1256466

Calling to-be-deprecated APIs out of scope for this task