sync/async requests and different content types

Feb 14, 2011 at 4:00 PM

Hey guys,

thanks for your help.
I have an additional question regarding requests which return only simple values and not XML or JSON like:$count
Do I have to write a custom handler for that? How does this work?

Another question: How can I trigger synchronous requests using datajs read/request? Is this already possible?

Best regards and keep up the good work!

Feb 14, 2011 at 8:53 PM

So far we haven't written the primitive value handlers, but we're open to doing it if it looks like a good option.

There are two main reasons why we haven't done this so far:

1. We can't do much better than reading the plain text response and returning that (the plain values don't have any annotations that tell us whether they are numbers, strings, dates, etc). At that point, we're pretty much equivalent to reading the responseText property of an XHR.

2. One of the nice things about datajs is how it can 'smooth out' differences, for example between reading from a local ATOM server to an other-domain JSON server. For primitive values however, JSONP may not work well. In particular, $count is always plain text and there is no JSON-based representation. So perhaps it's better that we "promise less" in this case.

That said, there area also arguments for implementing this, such as not having to pull in an additional library to work around XHR differences or just the consistency of plugging this along with the dance of httpClient, handlers and such.

I'd love to hear your thoughts on this.



Feb 14, 2011 at 10:14 PM

Hi Marcelo,

thank you for your help.

Yes you are right about this. I already thought on using for example jQuery for this simple requests.

And I also got it working by writing an own "plain handler" and implement the read method for it and return the value.

So both ways should work and you can decide if you want to use an additional library like jQuery (which most users do anyway I guess) or simply use only datajs to have it all packed in one library.

But to the other point I had: Are synchronous requests already possible like in jQuery where you can specify that?

That might be useful if you need a specific value before you can proceed to render for example a specific amount of rows in a table.


Feb 14, 2011 at 11:22 PM

Hi ironmanager,

No we do not currently have a jQuery-like flag for making requests synchronous. I am probably missing the details of your scenario, but couldn't you put the rendering code in the success callback of the request?


Feb 15, 2011 at 5:51 AM

To add to what David has mentioned, most proposed APIs for the browser use some form of asynchronous execution (IndexedDB and WebSocket comes to mind), certainly on the UI thread.

We think that making this style pervasive will make it easier to use everything together in the long run, and that often we can find better solutions at a higher level.

Also, thanks a ton for your feedback - it's good to know we're not the only ones who can see the plain value support going either way :) And more details around your scenario like David asked of course can only help us, so again, thank you for taking the time to talk to us.


May 23, 2013 at 6:29 AM
We are also looking for Sync read calls from Web Worker, please.