When I use createRecord and then save, the express server receives the post request but the req.body is empty. I made the same post request using Postman and it works perfectly. The get request works too in the tasks template displaying the tasks in a list.
This is my ember code:
Route (tasks.js):
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('task');
},
actions: {
addTask() {
const task = this.store.createRecord('task', {
title: this.get("controller.title")
});
task.save();
}
}
});
Model (task.js):
import Model from 'ember-data/model';
import DS from 'ember-data';
export default Model.extend({
title: DS.attr('string')
});
Template (tasks.hbs):
{{input value=title}}
<button id="add-task" {{action "addTask"}}>Add</button>
<br><br>
{{#each model as |task|}}
{{task.title}}<br>
{{/each}}
{{outlet}}
I'm using the default ember JSONAPIAdapter.
Ember and JSONAPIAdapter is sending the header with type application/vnd.api+json. I got it working by adding this in express.js:
app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With