Extension:WikiLambda/API
File:API - The Noun Project.svg | <translate> This page is part of the [[<tvar name="main">Special:MyLanguage/API:Main_page</tvar>|MediaWiki Action API]] documentation.</translate> |
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.
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 #list=wikilambdaload_zobjects
Documentation
Method: GET
Action: wikilambda_fetch
Request: api.php?action=wikilambda_fetch&format=json&zids=Z111|Z112&language=en
Response:
{
"Z111": {
"wikilambda_fetch": "{\n \"Z1K1\": \"Z2\",\n \"Z2K1\": \"Z111\"\n}"
},
"Z112": {
"wikilambda_fetch": "{\n \"Z1K1\": \"Z2\",\n \"Z2K1\": \"Z112\"\n}"
}
}
Parameters
name | description |
---|---|
zids
required | string |
List of ZObject Identifiers (ZIDs) to fetch, separated by pipes.
E.g. |
language
optional | string |
String code for the language in which to return the results. Must be an accepted MediaWiki language code. If not present, the API will return the root label in all available languages.
E.g. |
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.
error name | error type (Z50) | description |
---|---|---|
Invalid ZID | Z549
|
The given ZID is an invalid ZObject ID. This means that it does not follow the expected format of ID starting with the capital letter Z and followed by a natural number. |
ZID not found | Z500
|
The given ZID does not exist in this wiki. |
Examples
- api.php?action=wikilambda_fetch&format=json&zids=Z1
- Returns the canonical representation of the ZObject with ZID
Z1
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
Z1
,Z2
andZ3
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
Z4
andZ6
with its root-level label in Spanish or available fallback languages.
wikilambda_edit
This internal API should never be called by any code except written by the Wikifunctions development team, and certainly not relied upon. It can change contract at any time, without warning. |
Docs for internal team purposes only | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
This API allows to create/edit persisted ZObject pages in Wikifunctions. The API expects the parameter To create a new ZObject, the parameter To edit an existing ZObject, the parameter DocumentationMethod: GET Action: wikilambda_edit Request: api.php?action=wikilambda_edit&format=json&summary=TestSummary&zid=Z10001&zobject=<URL_ENCODED_JSON_OBJECT> Response: {
"wikilambda_edit": {
"success": "",
"articleId": 1096,
"title": "Z10001",
"page": "Z10001"
}
}
Parameters
Possible ErrorsThis 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
Examples
|
wikilambda_function_call
This internal API should never be called by any code except written by the Wikifunctions development team, and certainly not relied upon. It can change contract at any time, without warning. |
Docs for internal team purposes only | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
One of the entrypoints to the Wikifunctions orchestration and evaluation back-end. This API receives a required JSON formatted ZObject and sends it to the function-orchestrator services for it to be evaluated and returned. Hence, the ZObject sent must be a Z7/Function call. DocumentationMethod: GET Action: wikilambda_function_call Request: api.php?action=wikilambda_function_call&format=json&wikilambda_function_call_zobject=<URL_ENCODED_JSON_FUNCTION> Response: {
"query": {
"wikilambda_function_call": {
"Orchestrated": {
"success": "",
"data": "{\"Z1K1\":\"Z22\",\"Z22K1\":{\"Z1K1\":\"Z40\",\"Z40K1\":\"Z42\"},\"Z22K2\":\"Z23\"}"
}
}
}
}
Parameters
Possible ErrorsDescribe function-orchestrator and evaluator most probable errors
Examples
|
wikilambda_perform_test
This internal API should never be called by any code except written by the Wikifunctions development team, and certainly not relied upon. It can change contract at any time, without warning. |
Docs for internal team purposes only | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
This is an internal API endpoint to query test results for a ZFunction. Accepts a If a test result is up-to-date in the results database cache, it will be retrieved from there. Otherwise, the test will be run by a call to the WikiFunctions orchestrator. In addition, under certain conditions this API reorders the implementations of the given function and updates the function's DocumentationMethod: GET Action: wikilambda_perform_test Request: api.php?action=wikilambda_perform_test&format=json&wikilambda_perform_test_zfunction=Z813&wikilambda_perform_test_zimplementations=Z913& wikilambda_perform_test_ztesters=Z8130 Response: {
"query": {
"wikilambda_perform_test": [
{
"zFunctionId": "Z813",
"zImplementationId": "Z913",
"zTesterId": "Z8130",
"testMetadata": "...",
"validateStatus": "..."
}
]
}
}
Parameters
Possible ErrorsIf an error occurs when evaluating a given ZTester's Z20K2, this error will be found in the "errors" entry of the returned "testMetadata". The error may be of any sort returned by Other errors this API method may return:
Examples
|
wikilambdaload_zobjects
This internal API should never be called by any code except written by the Wikifunctions development team, and certainly not relied upon. It can change contract at any time, without warning. |
Docs for internal team purposes only | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Similarly to the DocumentationMethod: GET Action: query List: wikilambdaload_zobjects Request: api.php?action=query&format=json&list=wikilambdaload_zobjects&wikilambdaload_zids=Z111|Z112&wikilambdaload_language=en&wikilambdaload_canonical=1 Response: {
"batchcomplete": "",
"query": {
"wikilambdaload_zobjects": {
"Z111": {
"success": "",
"data": {
"Z1K1": "Z2",
"Z2K1": "Z111"
}
},
"Z112": {
"success": "",
"data": {
"Z1K1": "Z2",
"Z2K1": "Z112"
}
}
}
}
}
Parameters
Possible ErrorsUnlike 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
|
wikilambdasearch_labels
This internal API should never be called by any code except written by the Wikifunctions development team, and certainly not relied upon. It can change contract at any time, without warning. |
Docs for internal team purposes only | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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. DocumentationMethod: GET Action: query List: wikilambdasearch_labels 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: {
"batchcomplete": "",
"query": {
"wikilambdasearch_labels": [
{
"page_namespace": 0,
"page_title": "Z111",
"page_type": "Z111",
"return_type": null,
"label": "foo",
"is_primary": 1,
"page_id": 0,
"page_content_model": "zobject",
"page_lang": "eu"
}
]
}
}
Parameters
Possible ErrorsNone. When nothing is found it will return an empty list. Examples
wikilambdafn_search
This API query list searches for the IDs of all ZObjects associated with a provided DocumentationMethod: GET Action: query List: wikilambdafn_search Request: api.php?action=query&format=json&list=wikilambdafn_search&wikilambdafn_zfunction_id=Z801&wikilambdafn_type=Z20 Response: {
"batchcomplete": "",
"query": {
"wikilambdafn_search": [
"Z8010",
"Z8011",
"Z8012",
"Z8013"
]
}
}
Parameters
Possible ErrorsNone. When nothing is found it will return an empty list.
Examples
|
wikilambda_supported_programming_languages
This internal API should never be called by any code except written by the Wikifunctions development team, and certainly not relied upon. It can change contract at any time, without warning. |
Docs for internal team purposes only | |||||||||
---|---|---|---|---|---|---|---|---|---|
This is an internal API to retrieve the programming languages supported by the back-end evaluator service at the time of running, and so determine which languages to recommend to users on the front end. It takes no parameters. DocumentationMethod: GET Action: wikilambda_supported_programming_languages Request: api.php?action=wikilambda_supported_programming_languages Response:{
"query": {
"wikilambda_supported_programming_languages": {
"success": true,
"data": "[\"javascript-es2020\",\"javascript-es2019\",\"javascript-es2018\",\"javascript-es2017\",\"javascript-es2016\",\"javascript-es2015\",\"javascript\",\"python-3-9\",\"python-3-8\",\"python-3-7\",\"python-3\",\"python\"]"
}
}
}
Response content:
Possible ErrorsNone, unless the orchestrator back-end service doesn't respond. |