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.

action=wikilambda_edit
This API allows to create/edit persisted ZObject pages in Wikifunctions. The API expects the parameter  to be a valid JSON representation of the ZObject in its canonical form.

To create a new ZObject, the parameter  must be omitted, and Wikifunctions will find and assign the next available ZID. Also, the keys from the JSON ZObject that refer to its identity (for example,  or the values of   and  ), must be set to the Null Reference.

To edit an existing ZObject, the parameter  must have the ZID of the ZObject to edit (which will be the same one as the internal identity keys).

Documentation
Method: GET

Request: api.php?action=wikilambda_edit&format=json&summary=TestSummary&zid=Z10001&zobject=urlencode( {"Z1K1":"Z2","Z2K1":"Z10001",...} )

Response:

Possible Errors
This API can return a wide variety of errors, because the provided ZObject is parsed and validated against the canonical schemata. All the validation errors will be wrapped in a error of type. Apart from the validation errors, Wikifunctions can detect a variety of problems described below.

Examples

 * api.php?action=wikilambda_edit&format=json&summary=New zobject&zobject=urlencode( ZOBJECT )&token=%2B\
 * Where ZOBJECT is:
 * Creates and saves a new ZObject in the database (empty values) and returns the newly assigned ZID.
 * Creates and saves a new ZObject in the database (empty values) and returns the newly assigned ZID.


 * api.php?action=wikilambda_edit&format=json&summary=Edit zobject&zid=Z10004&zobject=urlencode( ZOBJECT )&token=%2B\
 * Where ZOBJECT is:
 * Edits the ZObject with title Z10004 and overwrites it with the given JSON ZObject.
 * Edits the ZObject with title Z10004 and overwrites it with the given JSON ZObject.

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 by their labels or aliases in a given language. It also provides a series of parameters that allow to filter by the ZObject type or by the return type of existing ZFunctions. It principally exists to support the look-ahead search system, and it's generally used in the front-end components that allow the user to search and select persisted ZObjects.

Documentation
Method: GET

Request: api.php?action=query&format=json&list=wikilambdasearch_labels&wikilambdasearch_search=foo&wikilambdasearch_language=eu&wikilambdasearch_type=Z4&wikilambdasearch_return_type=Z4&wikilambdasearch_strict_return_type=true

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.


 * api.php?action=query&format=json&list=wikilambdasearch_labels&wikilambdasearch_language=en&wikilambdasearch_return_type=Z40
 * Return the English label of every entry that has a ZBoolean (Z40) return type, including those that have a generic ZObject (Z1) return type.


 * api.php?action=query&format=json&list=wikilambdasearch_labels&wikilambdasearch_language=en&wikilambdasearch_return_type=Z40&wikilambdasearch_strict_return_type=true
 * Return the English label of every entry that has strictly a ZBoolean (Z40) return type.