api.router

Router api class with functions for communication with the backend.

All router functions are available through the context.api.router object.

router.postBinary(path, file, onProgress, onLoad, onError, params)

Post a binary file object to the backend

Param Type Description
path string
file object File object from file input or file drop
onProgress function Callback function for progress event
onLoad function Callback function for onload event
onError function
params function

router.post(path, parameters) ⇒ Promise.<Response>

Post data to specified backend endpoint

Param Type
path string
parameters object

router.put(path, parameters) ⇒ Promise.<Response>

Put data to specified backend endpoint

Param Type
path string
parameters object

router.get(path, parameters) ⇒ Promise.<Response>

Get data from specified backend endpoint

Param Type Description
path string
parameters object Could contain headers that will be passed along parameters.headers

Example

import {api} from 'writer'

api.router.get('/api/binary/url/' + uuid)
    .then((url) => {
        // Handle url
    })
    .catch((error) => {
        console.error(error);
    });

router.head(path, parameters) ⇒ Promise.<Response>

Fetch specified backend endpoint using a http HEAD request. This is silent and will not produce any error messages.

Param Type Description
path string
parameters object Could contain headers that will be passed along parameters.headers

Example

import {api} from 'writer'

api.router.head('/api/binary/url/' + uuid)
    .then((url) => {
        // Handle url
    })
    .catch((error) => {
        console.error(error);
    });

router.del(path, parameters) ⇒ Promise.<Response>

Make a DELETE call to a specified backend endpoint

Param Type Description
path string Backend endpoint
parameters object Key value request parameters

router.proxy(path, op) ⇒ object

Proxy ajax call to external backend

Returns: object - jQuery ajax object

Param Type
path string
op object

router.getConceptItem(id, imType) ⇒ *

Fetch a ConceptItem from the backend

Param Description
id The id of the concept
imType The x-im/type

router.getNewsItem(id, imType) ⇒ *

Fetch a NewsItem from the backend

Param Description
id The id of the news item
imType The x-im/type

router.updateConceptItem(uuid, concept) ⇒

Updates a Concept Item

Returns: A promise with no data

Param Description
uuid The uuid of the Concept Item to update
concept The updated XML

router.createConceptItem(concept) ⇒ * | Promise.<TResult>

Creates a Concept Item

Returns: * | Promise.<TResult> - containing the resulting UUID

Param Description
concept The concept to create

router.checkForOKStatus(response) ⇒ *

Method checks for a status code between 200 and 299 Throws error if otherwise.

Use for example when you want to reject a fetch promise

Param
response

Example

router.authorizedFetch(...)
    .then(response => checkForOKStatus(response))
    .then(response => toJson(response))
    .then(json => ...)
    .catch(error => ...)

router.toJson()

Deprecated

Use native response.json() instead

router.authorizedFetch(url, params) ⇒ Promise.<*>

Param Type
url
params object

results matching ""

    No results matching ""