Help with iron-ajax and asynchronous API calls (JSON etag sync and response handling)

343 views
Skip to first unread message

Kelly St. John

unread,
Nov 20, 2015, 3:41:57 PM11/20/15
to Polymer
Hi All,

I'm looking for a tried and true way of handling asynchronous calls to API endpoints returning JSON (using the iron-ajax element).  These API calls rely on etag matching, so it is important that the etag sent matches the one on the server.  I have that part working, except in certain circumstances, where quick succession API calls may cause an out-of-sequence response (and therefore can get the etag out of sync).  There are also multiple API endpoints (i.e. different URLs).  So, sometimes if quick succession calls using different endpoints are initiated via an iron-ajax element, it can cause issues for the response handler function, as the response handler currently checks the URL of the ajax element to know how to handle the response appropriately.  Therefore, if the 2nd call overwrites the URL of the ajax component before the 1st call response is received, when the 1st call does come back the responseHandler doesn't handle it appropriately.  Perhaps there is a much better and reliable way of checking exactly which call has returned?

I know I'm not the first person to encounter this scenario, so I'm wondering if someone out there can show me the enlightened path?  I'm sure there is a simple strategy to handle this problem, perhaps call queuing etc., but I'm not sure if iron-ajax has anything built-in that could help in that regard.

An example with some sample code would be absolutely stupendous!  I'll post a question on stack overflow as well and update the thread with the link.

Thanks!

Kelly St. John

unread,
Nov 20, 2015, 3:58:18 PM11/20/15
to Polymer
Reply all
Reply to author
Forward
0 new messages