I’m trying to make posts to my Django backend and I did some researches about it and found that Django requires a / at the end of post requests’ URLs.
The URL would be something like this: http://localhost:8000/users/.
I’m using the JSONAPIAdapter and I know that the post requests doesn’t have the /. That’s why I’m trying to override the adapter’s buildURL method to fit the requests to the backend.
I’m doing something like this inside my JSONAPIAdapter:
Thank you so much! It worked like a charm! About the return statement it was just a typo while I was writing this post.
The full adapter now looks like this:
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import ENV from 'gestao-hotelaria-dashboard/config/environment';
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
export default class ApplicationAdapter extends JSONAPIAdapter {
@service session;
host = ENV.APP.api;
@computed('session.data.authenticated.access_token')
get headers() {
let headers = {};
if (this.session.isAuthenticated) {
headers['Authorization'] = `Token ${this.session.data.authenticated.access_token}`;
}
return headers;
}
buildURL(modelName, id, snapshot, requestType, query){
if (requestType === 'createRecord') {
return super.buildURL(...arguments) + '/';
} else {
return super.buildURL(...arguments);
}
}
}