Extension:WikiLambda/API

The WikiLambda extension has a simple API for internal and external use. These APIs let you search and fetch WikiFunctions content and retrieve it in different formats and after different transformations.

These APIs are modules and submodules of MediaWiki Action API. You can make requests, explore the examples and see the results in the MediaWiki API Sandbox.

action=wikilambda_fetch
This API allows to retrieve one or more of ZObject pages from Wikifunctions. Every requested ZObject will be returned as a string encoding its canonical JSON representation. If a particular language is requested, the ZObject will return its root object label in the selected language (or fallbacks).

This API, designed as an Action API module, is created for its external use and hence the returned ZObjects are encoded as strings. For internal use in the Wikifunctions application, please see below the documentation of

Documentation
Method: GET

Request: api.php?action=wikilambda_fetch&format=json&zids=Z111|Z112&language=en

Response:

Possible Errors
This API expects no errors to be found. If any of the ZIDs is invalid or cannot be found, the returned object will consist solely on the found error and will not return the valid objects.

Examples

 * api.php?action=wikilambda_fetch&format=json&zids=Z1
 * Returns the canonical representation of the ZObject with ZID  with its labels in all available languages.


 * api.php?action=wikilambda_fetch&format=json&zids=Z1|Z2|Z3
 * Returns the canonical representation of the ZObjects with ZIDs,   and   with its labels in all available languages.


 * api.php?action=wikilambda_fetch&format=json&zids=Z4|Z6&language=es
 * Returns the canonical representation of the ZObjects with ZIDs  and   with its root-level label in Spanish or available fallback languages.

list=wikilambdaload_zobjects
Similarly to the  API detailed below, this API returns an aggregation of ZObject pages from Wikifunctions. This API is a list submodule of the  action=query API and is dedicated to extension-wide internal requests. The return format is an array with the valid JSON representation of the ZObjects requested. It provides different parameters to configure the type of format to serialize the ZObjects to (either normal or canonical form) and the language for the object labels.

Documentation
Method: GET

Request: api.php?action=query&format=json&list=wikilambdaload_zobjects&wikilambdaload_zids=Z111|Z112&wikilambdaload_language=en&wikilambdaload_canonical=1

Response:

Possible Errors
Unlike the wikilambda_fetch API, this API can handle errors while still returning the information of the ZObjects that have been found. The returned errors will also be ZObjects of type ZError (Z5). To distinguish between the return of an error in the API execution and the return of a requested ZError object, the response includes the value `success` for each of the requested `ZIDs`.

The possible errors that can be returned for an individual ZID are detailed below.

Examples

 * api.php?action=query&format=json&list=wikilambdaload_zobjects&wikilambdaload_zids=Z1|Z2
 * Returns the normal JSON representation of the ZObjects with ZID  and   with its labels in all available languages.


 * api.php?action=query&format=json&list=wikilambdaload_zobjects&wikilambdaload_zids=Z3|Z4&wikilambdaload_language=ay
 * Returns the normal JSON representation of the ZObjects with ZIDs  and   with all its ZMultilingual String (Z12) objects filtered to only return Aymaran labels. If an Aymaran label is not found, it will return those in any of the available fallback languages.


 * api.php?action=query&format=json&list=wikilambdaload_zobjects&wikilambdaload_zids=Z6&wikilambdaload_canonical=1
 * Returns the canonical representation of the ZObjects with ZID.

list=wikilambdasearch_labels
This API query list generator lets you search ZObjects for labels in a given language. It principally exists to support the look-ahead search system.

Documentation
Method: GET

Request: api.php?action=query&format=json&list=wikilambdasearch_labels&wikilambdasearch_search=foo&wikilambdasearch_language=eu

Response:

Possible Errors
None. When nothing is found it will return an empty list.

Examples

 * api.php?action=query&format=json&list=wikilambdasearch_labels&wikilambdasearch_search=ThisLabelDoesNotExist&wikilambdasearch_language=en
 * No labels in English match or contain the substring ThisLabelDoesNotExist, so an empty batch is returned.


 * api.php?action=query&format=json&list=wikilambdasearch_labels&wikilambdasearch_search=TEX&wikilambdasearch_language=en
 * Return every label matching or containing the substring TEX in English. This might ensure that at least two builtin ZObjects will be returned: Z12 "Multilingual text" and Z11 "Monolingual text".


 * api.php?action=query&format=json&list=wikilambdasearch_labels&wikilambdasearch_search=TEX&wikilambdasearch_language=en&wikilambdasearch_exact=1
 * Return every label matching or containing the exact substring TEX in English. This will not return the two ZObjects returned in the previous example, as this search is case-sensitive.