How to make arbitrary API calls using Ember.js?

What I'm trying to do is described here in great detail:

Server-side method call on RESTful path

I have an Ember Data RESTAdapter working with my API, but now I want to give Ember.js the ability to run various server-side actions using custom routes like /docs/1/share or /docs/1/activate . The former could have changed the record, but the latter would not.

What is the best way to do this?

TIA!

+6
source share
2 answers

Ember has jQuery baked inside. In your controller:

 actions: { activate: function() { var docId= this.get('id'), self= this; Ember.$.ajax({ url: '/docs/%@/activate'.fmt(docId), // your other details... }).then(function(resolve) { self.set('name', resolve.doc.name); // process the result... }); } } 
+7
source

You can also use ic-ajax , which is a nice wrapper around jQuery.ajax , here you can see an example using ix-ajax .

+2
source

Source: https://habr.com/ru/post/977037/


All Articles