lundi 15 avril 2019

What is the recommended way to make a PUT request to an external API in EmberJS?

I have a simple app that retrieves a record from an external API and displays the value ("day"). The day value can be incremented by passing it into a component with a simple action. My app is retrieving the record correctly and is successfully passing it to the component. But once it has incremented the value I can't figure out the best way to save the record back to the external API.

My route fetches the object like this:

export default Route.extend({
  model() {
    return this.get('store').findRecord('world', '5cb0f8bd3b74cf22b75e1a37', { reload: true });
  },
})

This is my model:

import Model from 'ember-data/model';
import DS from 'ember-data';

const { attr } = DS;

export default Model.extend({
  day: attr('Number'),
});

Here is my component:

import Component from '@ember/component';
import { inject as service } from '@ember/service';

export default Component.extend({
  router: service(),
  store: Ember.inject.service(),
  actions:{
    incrementHour() {
    this.day++;
    }
  }
});

Once this value has been incremented, what is the recommended way to push this back to the API?




Aucun commentaire:

Enregistrer un commentaire