JavaScript API asset


(Ryan Archer) #1

I'm just reading up in the Squiz User Guide and trying to figure out what the Javascript API does. What I 'think' I understand is that you can use this type of asset to access some APIs behind the Squiz Matrix system so you may be able to GET/PUSH content/functionality between a Squiz Matrix website and another non Squiz Matrix website?

 

I hope I am right. If anyone can quickly illustrate a use case scenario it would be more clear. What I think the asset does not do is allow us to easily access a third party API (preferably through AJAX/JSON) and get the content into a page asset. Currently I just hand code all this stuff in custom JS within a body copy div (or in a design file if its a sitewide thing).


(Anthony Ponomarenko) #2

Hey there, you are right, the following is taken from manuals:

 

"The Javascript API asset is used to enable the execution of core-level Squiz Matrix functions using JavaScript, allowing users to create, modify and retrieve content within the system. These functions are handled on the Details screen of the Javascript API asset. "


(Marcus Fong) #3

What I think the asset does not do is allow us to easily access a third party API (preferably through AJAX/JSON) and get the content into a page asset.

I’m pretty sure displaying third-party API content in Matrix is usually done via REST Resource JavaScript assets, where the “JavaScript” refers to JavaScript processing on the Matrix server using either the SpiderMonkey (Firefox) or V8JS (Chrome) JS engines.


If you want to, you can put the REST JS asset on a separate URL from the rest of your content and call it into your pages via AJAX. That’s not uncommon as a method of maximising cache efficiency - the AJAXed REST JS content can have a very short cache lifetime or be uncached, while the rest of the page is cached normally.


(Note that if you want to process JSON easily then you’ll generally want to either use V8JS or have a newer version of SpiderMonkey installed. Alternatively, some people prefer to use their own third-party JSON-parsing libraries.)


(Ryan Archer) #4

Good points you make there Marcus. I am encouraged to follow that workflow in the future. I use Postman Chrome extension for testing APIs and JSONView addon in Firefox for parsing JSON.