[MGNLRESTCL-47] Asynchronous REST calls from templates Created: 14/Feb/19  Updated: 24/Oct/19

Status: Open
Project: REST Client
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Story Priority: Neutral
Reporter: Christopher Zimmermann Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Release notes required:
Yes
Documentation update required:
Yes
Epic Link: Easy Outbound REST
Sprint: Phase 2

 Description   

As a template developer I want to make asynchronous calls to REST endpoints in my template and also include the results asynchronously, so that I can use both local and external content in my web experiences, in an efficient manner.

For Example:

Some content is of secondary importance such as offers and promotions. Even if the external system where you are getting the promos is slow to respond, you still want to render the primary content of your site immediately. The promos can show a loading indicator and then load later.

Acceptance Criteria:

  • REST calls are performed from the server so that credentials are not exposed and to avoid problems with CORS.
  • Easy pattern to follow.
  • Errors in the REST response are handled gracefully.

NOTE: This does not require a change to the rendering pipeline. Could maybe be resolved by documentation and examples.

Possible approach: Component renders a loading indicator and includes javascript to make an ajax request to another variant of itself using Direct Component Rendering and a different file extension. When this variant of the component is requested (via this file extension), it then makes the normal synchronous restfn call and renders itself (either as JSON or HTML depending on the usecase). When this rendering is returned to the JS that made the AJAX request, either the JS creates some markup based on the returned JSON, or the pre-rendered HTML is injected in the DOM.



 Comments   
Comment by Christopher Zimmermann [ 24/Oct/19 ]

Here is a proposal for a technique which could be included in documentation: 

https://git.magnolia-cms.com/users/czimmermann/repos/restclient-testing/browse/light-modules/rc-async-resfn-demo/templates/components/joke.ftl

Generated at Mon Feb 12 10:42:41 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.