APIRequester
MMO.core · 2 symbols · generated 5 Oct 2026
APIRequester
APIRequester.js:14Wrapper to query any API implementing JSON API
- Namespace
MMO.core
Index
| collection readonly accessor | The collection name, read back out of the url through the repository path pattern. | |
| repository readonly accessor | The repository name, read back out of the url through the repository path pattern. | |
| offset accessor | Get the starting offset of the data | |
| limit accessor | Get the maximum number of data to return | |
| sort accessor | Get a list of the fields used to sort the data the value associated to the field is a boolean that indicates if the sorting is ascending (false for descending) | |
| fields accessor | Get a list of the fields to show the value associated to the field is a boolean that indicates if the field is shown (true) or hidden (false) | |
| filters accessor | The query filters, as a plain object. | |
| search accessor | The full text search parameters, as a plain object. | |
| searchType accessor | ||
| dataCount readonly accessor | ||
| dataClass readonly accessor | The php class name of the entities the last response carried. | |
| pageOffset readonly accessor | The index of the first entity of the last response, within the whole collection. | |
| pageIndex readonly accessor | The page number of the last response. | |
| pageCount readonly accessor | How many pages the query spans. | |
| previousPageUrl readonly accessor | ||
| nextPageUrl readonly accessor | ||
| firstPageUrl readonly accessor | ||
| lastPageUrl readonly accessor | ||
| constructor(url) | ||
| setUrl(url, keepSearch) | Point the requester at another url, rebuilding its search parameters. | |
| setUrlSearch(search) | Replace the whole query string. | |
| Collection(collection, repository) static | Get an instance meant to interact with the framework repository controller | |
| List(collection, filters, repository) static | A requester set up to return identifiers only: ideal to populate a picker. | |
| setLimitDate(dateStart, dateEnd, dateField) | Restrict the query to a date window, replacing any window already set on that field. | |
| getLimitDate(dateField) | Read back the window set by MMO.core.APIRequester#setLimitDate | |
| splitFieldsList(key) | Split a string representing a list of fields | |
| joinFieldsList(key, value) | Join a value to create a list of fields as a string | |
| indexOfFieldsList(key, field, value) | Get/set the index of field (even if the field is prefixed with '-') | |
| indexAtFieldsList(key, index) | ||
| addFieldsList(key, field, value, order) | Add a field to the field list | |
| removeFieldsList(key, field) | Remove a field from the field list | |
| getSortParam() | ||
| isSortOnlyId() | ||
| clearSort() | Drop the sorting, letting the server apply its own order. | |
| isEmptySort() | ||
| addSort(field, asc, order) | Add a field to the sort, or move one already there. | |
| removeSort(field) | ||
| indexOfSort(field, value) | Read, or change, a sort field's position. | |
| indexAtSort(index) | ||
| listOnly(value) | Only return a list of identifier | |
| clearFields() | Drop the field selection, asking the server for everything it exposes. | |
| getFieldsParam() | ||
| addField(field, visible, order) | Add a field to the selection, or move one already there. | |
| removeField(field) | ||
| indexOfField(field, value) | Read, or change, a field's position. | |
| indexAtField(index) | ||
| setSearchValue(key, value) | Set one search parameter, leaving the others alone. | |
| fetch(data, opts, method) | Run the query, aborting any request this requester still had in flight. | |
| fetchXLSX(fields, opts) | Download the current query as a spreadsheet, by swapping the url's extension. | |
| fetchCSV(fields, opts) | Download the current query as a csv file. | |
| fetchJSON(fields, opts) | Download the current query as a json file. | |
| abort() | Abort fetch | |
| get(ids) | Get entities | |
| update(data, opts) | Update entities (MUST have ids) | |
| insert(data, opts) | Insert entities (NO ids) | |
| remove(data, opts) | Delete entities (MUST have ids) | |
| patch(data, opts) | Send a patch request that allows setting the status of an entity | |
| setPreviousUrl() | Set api's url to the previous page NOTE: this only change the url. | |
| setNextUrl() | Set api's url to the next page NOTE: this only change the url. |
Properties18
collection
readonlyaccessorAPIRequester.js:48The collection name, read back out of the url through the repository path pattern.
- Type
?string
repository
readonlyaccessorAPIRequester.js:56The repository name, read back out of the url through the repository path pattern.
- Type
?string
offset
accessorAPIRequester.js:92Get the starting offset of the data
limit
accessorAPIRequester.js:108Get the maximum number of data to return
sort
accessorAPIRequester.js:300Get a list of the fields used to sort the data the value associated to the field is a boolean that indicates if the sorting is ascending (false for descending)
fields
accessorAPIRequester.js:405Get a list of the fields to show the value associated to the field is a boolean that indicates if the field is shown (true) or hidden (false)
filters
accessorAPIRequester.js:469The query filters, as a plain object. Operators are nested: {age: {'$gte': 20}}.
- Type
Object
search
accessorAPIRequester.js:493The full text search parameters, as a plain object.
- Type
Object
searchType
accessorAPIRequester.js:518- Type
?string
dataCount
readonlyaccessorAPIRequester.js:690dataClass
readonlyaccessorAPIRequester.js:698The php class name of the entities the last response carried.
- Type
?string
pageOffset
readonlyaccessorAPIRequester.js:706The index of the first entity of the last response, within the whole collection.
- Type
?number
pageIndex
readonlyaccessorAPIRequester.js:714The page number of the last response.
- Type
?number
pageCount
readonlyaccessorAPIRequester.js:722How many pages the query spans.
- Type
?number
previousPageUrl
readonlyaccessorAPIRequester.js:729- Type
?string
nextPageUrl
readonlyaccessorAPIRequester.js:750- Type
?string
firstPageUrl
readonlyaccessorAPIRequester.js:771- Type
?string
lastPageUrl
readonlyaccessorAPIRequester.js:778- Type
?string
Methods41
constructor(url)
APIRequester.js:15| url = '' |
setUrl(url, keepSearch)
APIRequester.js:28Point the requester at another url, rebuilding its search parameters.
| url | string | URL | resolved against the site url when relative |
| keepSearch = false | boolean | carry the current query over to the new url |
setUrlSearch(search)
APIRequester.js:39Replace the whole query string.
| search | string | with or without its leading '?' |
Collection(collection, repository)
staticAPIRequester.js:67Get an instance meant to interact with the framework repository controller
| collection | ||
| repository = null | ||
| returns | MMO.core.APIRequester |
List(collection, filters, repository)
staticAPIRequester.js:78A requester set up to return identifiers only: ideal to populate a picker.
| collection | string | |
| filters | Object | |
| repository = null | ?string | defaults to 'main' |
| returns | MMO.core.APIRequester |
setLimitDate(dateStart, dateEnd, dateField)
APIRequester.js:128Restrict the query to a date window, replacing any window already set on that field.
| dateStart | Date | string | |
| dateEnd | Date | string | |
| dateField = 'ctime' | string | the entity property carrying the date |
getLimitDate(dateField)
APIRequester.js:153Read back the window set by MMO.core.APIRequester#setLimitDate
| dateField = 'ctime' | string | |
| returns | ?[?string, ?string] | null when no window is set |
splitFieldsList(key)
APIRequester.js:179Split a string representing a list of fields
| key | string | the key in the searchParams |
| returns | field: boolean | } |
joinFieldsList(key, value)
APIRequester.js:198Join a value to create a list of fields as a string
| key | string | the key in the searchParams |
| value | string | Array | Object | - a string: list of field's name separated by comma. use - as a field prefix to set value to false. - an array: list of field's name - an object: {field}: {boolean} |
| returns | string |
indexOfFieldsList(key, field, value)
APIRequester.js:215Get/set the index of field (even if the field is prefixed with '-')
| key | string | the key in the searchParams |
| field | string | the field's name (can be prefixed with '-') |
| value = null | int | null | if not null, move the field to this index |
| returns | number | -1 if the field was not found |
indexAtFieldsList(key, index)
APIRequester.js:239| key | string | the key in the searchParams |
| index | number | |
| returns | ?string | the field at that position, with its prefix; null when out of range |
addFieldsList(key, field, value, order)
APIRequester.js:252Add a field to the field list
| key | string | the key in the searchParams |
| field | string | the field's name (can be prefixed with '-') |
| value = null | boolean | null | if null, will use the field as it is (with/without its prefix), else force the prefix on the field |
| order = null | ||
| returns | number | -1 if the field was not found |
removeFieldsList(key, field)
APIRequester.js:283Remove a field from the field list
| key | string | the key in the searchParams |
| field | string | the field's name (can be prefixed with '-') |
| returns | boolean | true if field was removed |
getSortParam()
APIRequester.js:315| returns | string | the raw sort parameter, '' when unset |
isSortOnlyId()
APIRequester.js:322| returns | boolean | true when the result is sorted by id and nothing else |
clearSort()
APIRequester.js:330Drop the sorting, letting the server apply its own order.
isEmptySort()
APIRequester.js:337| returns | boolean | true when sorting is explicitly set to nothing (NOT the same as unset) |
addSort(field, asc, order)
APIRequester.js:348Add a field to the sort, or move one already there.
| field | string | prefix with '-' for a descending sort |
| asc = null | ?boolean | force the direction, ignoring the field's own prefix |
| order = null | ?number | the position among the sort fields; appended when null |
| returns | number | the field's position |
removeSort(field)
APIRequester.js:356| field | string | with or without its prefix |
| returns | boolean | false when the field was not part of the sort |
indexOfSort(field, value)
APIRequester.js:366Read, or change, a sort field's position.
| field | string | with or without its prefix |
| value = null | ?number | move the field to this position |
| returns | number | the position, -1 when the field is not part of the sort |
indexAtSort(index)
APIRequester.js:374| index | number | |
| returns | ?string | the sort field at that position |
listOnly(value)
APIRequester.js:385Only return a list of identifier
| value = true |
clearFields()
APIRequester.js:396Drop the field selection, asking the server for everything it exposes.
getFieldsParam()
APIRequester.js:419| returns | string | the raw fields parameter, '' when unset |
addField(field, visible, order)
APIRequester.js:430Add a field to the selection, or move one already there.
| field | string | prefix with '-' to hide it |
| visible = null | ?boolean | force the visibility, ignoring the field's own prefix |
| order = null | ?number | the position among the fields; appended when null |
| returns | number | the field's position |
removeField(field)
APIRequester.js:438| field | string | with or without its prefix |
| returns | boolean | false when the field was not part of the selection |
indexOfField(field, value)
APIRequester.js:448Read, or change, a field's position.
| field | string | with or without its prefix |
| value = null | ?number | move the field to this position |
| returns | number | the position, -1 when the field is not selected |
indexAtField(index)
APIRequester.js:456| index | number | |
| returns | ?string | the field at that position |
setSearchValue(key, value)
APIRequester.js:510Set one search parameter, leaving the others alone.
| key | string | |
| value | * | null or undefined drops it |
fetch(data, opts, method)
APIRequester.js:541Run the query, aborting any request this requester still had in flight.
| data = null | ?(Object | Array) | a body; a GET carries it in the query string instead |
| opts = {} | Object | options for the Request |
| method = null | ?string | defaults to GET without data, POST with |
| returns | Promise<Object> | the entities, indexed by uid |
fetchXLSX(fields, opts)
APIRequester.js:581Download the current query as a spreadsheet, by swapping the url's extension.
| fields = null | ?Array<string> | export these fields instead of the selected ones |
| opts = {} | Object | options for the Request |
| returns | Promise<Blob> |
fetchCSV(fields, opts)
APIRequester.js:595Download the current query as a csv file.
| fields = null | ?Array<string> | export these fields instead of the selected ones |
| opts = {} | Object | options for the Request |
| returns | Promise<Blob> |
fetchJSON(fields, opts)
APIRequester.js:610Download the current query as a json file.
| fields = null | ?Array<string> | export these fields instead of the selected ones |
| opts = {} | Object | options for the Request |
| returns | Promise<Blob> |
abort()
APIRequester.js:621Abort fetch
get(ids)
APIRequester.js:635Get entities
| ids = null | array | string | int | null | the ids to look for. if null, load everything |
| returns | Promise<*> |
update(data, opts)
APIRequester.js:653Update entities (MUST have ids)
| data | MMO.elements.Entity | object | Array | to send (can be multiple entities or just one) |
| opts = {} | object | the options to pass to the request (see documentation of javascript Request) |
| returns | Promise<*> |
insert(data, opts)
APIRequester.js:663Insert entities (NO ids)
| data | MMO.elements.Entity | object | Array | to send (can be multiple entities or just one) |
| opts = {} | object | the options to pass to the request (see documentation of javascript Request) |
| returns | Promise<*> |
remove(data, opts)
APIRequester.js:673Delete entities (MUST have ids)
| data | MMO.elements.Entity | object | Array | to send (can be multiple entities or just one). only ids are required |
| opts = {} | object | the options to pass to the request (see documentation of javascript Request) |
| returns | Promise<*> |
patch(data, opts)
APIRequester.js:683Send a patch request that allows setting the status of an entity
| data | object | {id, status} |
| opts = {} | object | the options to pass to the request (see documentation of javascript Request) |
| returns | Promise<*> |
setPreviousUrl()
APIRequester.js:738Set api's url to the previous page NOTE: this only change the url. You still need to call fetch().
| returns | boolean | true if the url was set |
setNextUrl()
APIRequester.js:759Set api's url to the next page NOTE: this only change the url. You still need to call fetch().
| returns | boolean | true if the url was set |
REGEX_FILTER
APIRequester.js:783- Namespace
MMO.core.APIRequester