Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESTAdapter Access to jqXHR / Response Headers #595

Closed
kstevens715 opened this issue Jan 8, 2013 · 3 comments
Closed

RESTAdapter Access to jqXHR / Response Headers #595

kstevens715 opened this issue Jan 8, 2013 · 3 comments
Labels
🏷️ feat This PR introduces a new feature

Comments

@kstevens715
Copy link

Let me describe the particular use-case I am currently considering. I have a reusable datatable view that allows sorting, pagination, etc. In order for this to work, I need the server to return metadata relating to the query results, such as total record count.

Currently, I'm doing this by adding attributes to my model. It works, but it's not very clean. A better solution, would be to include the metadata in the response headers. Unfortunately, the current RESTAdapter doesn't make it easy to get at the response headers.

It would be extremely useful if the jqXHR object returned by jQuery's ajax() method could somehow be made available when performing ajax calls. This would allow access to headers, response codes, etc. This would be useful whether the call resulted in success or error, and I believe it would be relevant to many more use cases than the particular one I've given as an example.

I imagine something like:

var products = App.Product.find(); // returns DS.RecordArray
var jqxhr = products.get('jqXHR')
jqxhr.getResponseHeader()

Does anyone else think this is useful and belongs in the core RESTAdapter? Thank you!

@tchak
Copy link
Member

tchak commented Jan 8, 2013

The role of adapter is to abstract it backend from the store. You should not be able to make a diference beween a model coming from RESTAdapter and IndexedDBAdaper. It is part of the "contract" Ember Data establish.
But I think we could have some hooks in RESTAdapter to ease filling model with some infos from headers or status codes. We definitively have some plans for a better error handeling, witch will transform in case of RESTAdapter, status codes in to meaningful backend independent errors. As for headers, we have a meta mechanism already in place, maybe it could be expanded.

@kstevens715
Copy link
Author

@tchak, that makes sense. As long as I have access to that data, that's all I'm looking for. Is there anyway you could explain the meta mechanism that you're talking about, or perhaps point me to the place in the source? Perhaps I could work on a pull request.

@wagenet
Copy link
Member

wagenet commented Aug 10, 2013

The adapter's didFindQuery is called with the recordArray and you can define arbitrary properties on it as you desire. This won't help with find all however since the mechanism is different and not directly tied to a single request. The default RESTAdapter does have a didError callback that gets passed the XHR object. If necessary, you can override that method for your own handling.

@wagenet wagenet closed this as completed Aug 10, 2013
@runspired runspired added 🏷️ feat This PR introduces a new feature and removed Improvement labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ feat This PR introduces a new feature
Projects
None yet
Development

No branches or pull requests

4 participants