Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (hash.data) {
// GET and HEAD requests can't have a `body`
if (hash.method === 'GET' || hash.method === 'HEAD') {
// If no options are passed, Ember Data sets `data` to an empty object, which we test for.
if (Object.keys(hash.data).length) {
// Test if there are already query params in the url (mimics jQuey.ajax).
const queryParamDelimiter = hash.url.indexOf('?') > -1 ? '&' : '?';
hash.url += `${queryParamDelimiter}${serializeQueryParams(hash.data)}`;
}
} else {
// NOTE: a request's body cannot be a POJO, so we stringify it if it is.
// JSON.stringify removes keys with values of `undefined` (mimics jQuery.ajax).
// If the data is not a POJO (it's a String, FormData, etc), we just set it.
// If the data is a string, we assume it's a stringified object.
if (isPlainObject(hash.data)) {
hash.body = JSON.stringify(hash.data);
} else {
hash.body = hash.data;
}
}
}
return hash;
}
model: function() {
return hash({
fetch: fetch('/omg.json').then(function(request) {
return request.json();
}),
ajax: ajax('/omg.json')
});
}
});
model: function() {
return hash({
fetch: fetch('/omg.json').then(function(request) {
return request.json();
}),
request: fetch(new Request('/omg.json')).then(function(request) {
return request.json();
}),
ajax: ajax('/omg.json')
});
}
});
setupUrl(requestUrl, method, options) {
const { host = '', data } = options;
const baseUrl = `${host}${requestUrl}`;
if (data && this.isRetrieve(method)) {
const params = serializeQueryParams(data);
const delimeter = baseUrl.indexOf('?') === -1 ? '?' : '&';
return `${baseUrl}${delimeter}${params}`;
}
return baseUrl;
},