Merge pull request #21742 from inkless/master

[ember-data] add ajax and ajaxOptions to RESTAdapter
This commit is contained in:
Armando Aguirre
2017-11-27 16:16:55 -08:00
committed by GitHub
2 changed files with 39 additions and 0 deletions

View File

@@ -1033,6 +1033,14 @@ declare namespace DS {
* should use the REST adapter.
*/
class RESTAdapter extends Adapter implements BuildURLMixin {
/**
* Takes a URL, an HTTP method and a hash of data, and makes an HTTP request.
*/
ajax(url: string, type: string, options?: object): Promise<any>;
/**
* Generate ajax options
*/
ajaxOptions(url: string, type: string, options?: object): object;
/**
* By default, the RESTAdapter will send the query params sorted alphabetically to the
* server.

View File

@@ -23,3 +23,34 @@ const AuthTokenHeader = DS.JSONAPIAdapter.extend({
};
})
});
const UseAjax = DS.JSONAPIAdapter.extend({
query(store: DS.Store, type: string, query: object) {
const url = 'https://api.example.com/my-api';
return this.ajax(url, 'POST', {
param: 'foo'
});
}
});
const UseAjaxOptions = DS.JSONAPIAdapter.extend({
query(store: DS.Store, type: string, query: object) {
const url = 'https://api.example.com/my-api';
const options = this.ajaxOptions(url, 'DELETE', {
foo: 'bar'
});
return Ember.$.ajax(url, {
...options
});
}
});
const UseAjaxOptionsWithOptionalThirdParams = DS.JSONAPIAdapter.extend({
query(store: DS.Store, type: string, query: object) {
const url = 'https://api.example.com/my-api';
const options = this.ajaxOptions(url, 'DELETE');
return Ember.$.ajax(url, {
...options
});
}
});