Wiki

Clone wiki

responsive-base / documentation / api

API

There is a simple interface to the REST-api exposed as J.api

All GET functions have an optional cache to local storage, use this to speed up page rendering and overall performance.

Structure

All getter methods need 4 standard arguments:

callback function or object

callbackOptions object/variable/array/whatever

enableCache bool, true will enable caching

cacheMinutes int representing minutes to to cache item

Example: J.api.category.list(categoryRender, {}, true, 5)

This will list all categories with function categoryRender as a callback, empty object {} as callbackOption.

Result will be cached for 5 minutes

Callback object

Normally a function are passed, but a object can be used for more complex functionality, where four named methods are tied to standard AJAX methods:

#!js
callbackObject = {

    before: function(callbackOptions) {},

    success: function(data, callbackOptions, textStatus, jqXHR) {},

    error: function(callbackOptions, xhr, ajaxOptions, thrownError) {},

    complete: function(data, callbackOptions, event, xhr) {},

}; 

Methods

###J.api.category###

list List all categories

get (id, displayType) Get specific category

getProducts (id, full, rows, page) Get all products associated with a category

###J.api.page###

list List all pages

get (id) Get specific page

###J.api.product###

get (id) Get specific product

getRelatedProducts (id) Get related products for a specific product

###J.api.search###

Single method (string, full, rows, page)

###J.api.settings###

get Get shop settings

###J.api.startpage###

list List all startpages

get (id) Get a specific startpage

active Get a specific startpage (will return id & type, not a full object)

Private functions

J.api.helpers.baseUrl(includeCulture, includeCurrency)

Returns a proper base-URL for REST

J.api.helpers.clearCache

Removes all cached objects in LocalStorage. Uses J.config.apiCachePrefix.

J.api.helpers.getAjax

The 'actual' function to GET using AJAX. Called by J.api.helpers.getter if object do not exist in cache.

J.api.helpers.getter

Interface for GET, this function will cache objects if possible. Called by all endpoint-functions. Suitable for custom calls.

J.api.helpers.initCache

Init for cache-handling. Will trigger J.api.helpers.clearCache() if user changes VAT.

J.api.helpers.isQuotaExceeded

Used to handle quotas in LocalStorage. If quota are exceeded object will not be cached.

J.api.helpers.raiseError

Will log to console.error for now, suitable for extension in the future.

J.api.helpers.read

Read from LocalStorage.

J.api.helpers.save

Save to LocalStorage.

Using services directly

Helper function api.helpers.getter can take argument "service" as a string for regular lookups in all endpoints.

The arguments for this functions are a bit more extensive:

J.api.helpers.getter(service, callback, callbackOptions, enableCache, cacheMinutes, includeCulture, includeCurrency)

Updated