Repository navigation
Improved ajax - #171
Improved ajax#171pangratz wants to merge 4 commits into
Conversation
|
If we're going through this effort is it worth trying to build something that decouples us from the underlying jQuery implementation? There is hopefully a future in which we don't ship that by default and it would be sad to require jQuery just for |
|
@nathanhammond yep, I definitely agree. The hooks should be designed to be agnostic of the specific library/implementation which does the actual request. I forgot to mention that explicitly in the RFC... |
|
@nathanhammond fetch maybe? |
- `makeRequest` is public - smaller adjustments
|
I think the hooks as described in this RFC have no dependency on One suggestion I have is that we are passing to There is a spec for a |
| let headers = this.headersForRequest(params); | ||
| let body = this.bodyForRequest(params); | ||
|
|
||
| return RSVP.hash({ method, url, headers, body }); |
There was a problem hiding this comment.
Should _requestFor be made a public method in case the user wants to add some other config property?
There was a problem hiding this comment.
and it could return a "standard" Request object :)
| @param request Object containing all properties for the request which should be made | ||
| @return Promise | ||
| */ | ||
| makeRequest(request) { |
There was a problem hiding this comment.
I think we should enumerate all of the properties Ember Data expects/supports on the request object.
There was a problem hiding this comment.
Based on my reading of this rfc it looks like it supports url, method, headers and body. With the exception of url all of these properties are shared by the 2nd argument to fetch (See: https://fetch.spec.whatwg.org/#requestinit). Which may lead a user to believe it supports all the properties that fetch supports.
This leads me to ask 2 questions.
- How much of the RequestInit api should Ember Data implement?
- Should the
urlproperty be pulled out of the request object andmakeRequestAPI be change to align more closely with thefetchapi?makeRequest(url, requestInit)
There was a problem hiding this comment.
fetch can also take a single argument with Request instance. This is kinda what I was proposing in my other comments. But align makeRequest with fetch options is 👍
|
@tchak I'm not sold on a |
|
@pangratz in response to you unresolved questions section at the end of the rfc.
I'm in favor of renaming
Again I like this change but I don't feel very strongly about it.
I do not think we need any more hooks inside
I was originally thinking 2 possible approches:
|
| warning("use queryForRequest to specify query params"); | ||
| } else if (query) { | ||
| let sortedQueryParams = this.sortQueryParams(query); | ||
| let queryParams = Ember.$.param(sortedQueryParams); |
There was a problem hiding this comment.
I think we may want to expose a public method for serializing query params that users can override if needed.
There was a problem hiding this comment.
You mean additionally to queryForRequest?
There was a problem hiding this comment.
Yes. Something that transforms the object returned from queryForRequest() into a string.
There was a problem hiding this comment.
Hmm, I see. Maybe queryStringForRequest()?
But then we would have 5 hooks which are involved getting the URL for a request:
urlForRequestpathForRequestqueryForRequestsortQueryParamsqueryStringForRequest
For now I am not convinced that an additional hook is necessary. Can you think of an use case where such a hook would come in handy?
There was a problem hiding this comment.
I've seen a few comments on slack recently were people want arrays or nested query params to be serialized differently from how $.param does it.
I wonder how widely used sortQueryParams is and I wonder if we could deprecate that and let users do that work in queryForRequest or queryStringForRequest if they need it.
There was a problem hiding this comment.
Ah, arrays and nested queries are definitely a valid use case 👍
Deprecating sortQueryParams in favor of queryStringForRequest sounds reasonable to me!
| ##### `methodForRequest` | ||
|
|
||
| Invoked to get the HTTP method for the request. Should return one of `"GET"`, | ||
| `"PUT"`, `"POST"` or `"DELETE"`. |
|
This will help resolve some issues we've had with ember-data-url-templates :) |
Fix incorrect docs about headersForRequest being used for ember-data versions >= 2.7. This is on hold until emberjs/rfcs#171 gets resolved
Fix incorrect docs about headersForRequest being used for ember-data versions >= 2.7. This is on hold until emberjs/rfcs#171 gets resolved
* Update data-adapter-mixin.js Fix incorrect docs about headersForRequest being used for ember-data versions >= 2.7. This is on hold until emberjs/rfcs#171 gets resolved * Update data-adapter-mixin.js
|
This seems to have fallen idle. This would be much needed in order the build a reasonable compatibility layer to be able to swap jQuery by just raw fetch. Is there any open question or significant pushback from anyone that prevents this from advancing? |
* Update data-adapter-mixin.js Fix incorrect docs about headersForRequest being used for ember-data versions >= 2.7. This is on hold until emberjs/rfcs#171 gets resolved * Update data-adapter-mixin.js
|
Same as above comment. It has been a while, it would be great to know where it's at or where it is on the timeline. Will be happy to contribute to speed it up, if anything at all is needed. The fact that https://emberjs.com/api/ember-data/2.16/classes/DS.RESTAdapter/methods/headersForRequest?anchor=headersForRequest is still in the docs but can not be used isn't ideal. |
|
Her is the list of remarks and concerns so far on this RFC:
"make things more standard":
|
|
@emberjs/ember-data-contributors @igorT what do we need to do to make progress on these questions? |
|
Regarding It's common to append authentication/session tokens in headers, and they may be stored asynchronously (for example in IndexedDB). |
@tchak is this polyfillable? This isn't supported by Internet Explorer natively. |
|
Where are we on this? Is this still a direction we would like to go? |
|
@rwjblue I think we want to finish migration to |
|
Closing as we are definitely moving in a very different direction. Keep your eyes open for a new RFC :) |
Rendered