How can I make a request to e.g. /videos/:id/related? using Ember Data and RESTAdapter to fetch objects of video type?
You can use the DS.RESTAdapter. It does exactly what you want. Check out these links:
http://emberjs.com/api/data/classes/DS.RESTAdapter.html
http://emberjs.com/guides/models/the-rest-adapter/
http://emberjs.com/guides/models/connecting-to-an-http-server/
EDIT:
Try using the findHasMany hook
http://emberjs.com/api/data/classes/DS.RESTAdapter.html#method_findHasMany
Related
im building a password update module on my Ember App. My API it's designed as:
PUT users/:id/password
so you should pass
{
currentpass: "123456",
newpass: "123456"
}
Is it possible and recommendable to use Ember DS for this case? What approach do you guys recommend? A different API design? no Ember Data ?
Regards!
I ended up using ember-api-actions. So i can use nested resources along with Ember Data
I've just finished upgrading my app to use the jj-abrams branch of ember-simple-auth (soon to be 1.0).
It's working great when I use ember data but, for one route, I use Ember.$.getJSON to retrieve chart data directly from the server.
In this instance, the authorization header is missing from the request and I'm guessing that's because it doesn't use the application adapter (therefore bypassing authorizer: 'authorizer:devise')?
Is there a way to add this header manually, or a better way to make this request?
Sure you can just include the session then you should have access to the credentials and use whatever you need to add those to your Router (I'm assuming it's using the AuthenticatedRouteMixin on your router.
Or for your controller add:
session: Ember.inject.service('session')
then you can do a get:
this.get('session')
and examine the object to find what you need in there, I believe that should make it easier for you to run without using Ember-Data.
I am trying to figure out how to get data from a custom api. I am using Ember 1.8.1, Ember Data 1.0.0-beta.12 and Ember CLI
In my router i have the following resource
this.resource("communities", {path: '/communities/:community-id/follow-ups'}, function() {});
I have my model defined for the correct response. In my communities router I am trying to get the data from the api like so
this.store.find('community', params['community-id']);
The problem I am having is that I am trying to retrive data from the api endpoint
/communities/{community-id}/follow-ups
But the app is trying to grab the data from
/communities/{community-id}
How do I define the custom resource route to pull from the follow-ups
The router path isn't going to change where the API makes the call to, that just helps Ember change the browser path.
You might want to consider using an adapter if you really need it to hit .../follow-ups.
You'd want to make a CommunitiesAdapter I think. ember g adapter communities, or community, not sure offhand.
And I think the function on it you're looking for is pathForType.
Check it out at http://guides.emberjs.com/v1.10.0/models/customizing-adapters/
You can create a custom adapter for your model in particular but deep nesting on routes can be tricky in Ember and not worth the time if you are in a rush.
Try setting the model of the route directly with a get json
App.NAMERoute = Ember.Route.extend({
model : function(params){
return Ember.$.getJSON(window.apiHost+'/communities/'+params.group_id+'/follow-ups');
}
});
Sometimes simple solutions is what you need
I'd like to get my model from an api and passing my current position so I can get the 10 closest.
The server does the calculation and limits to 10 already.
What would be the best approach to load the data while passing the location params. knowing that I would like the application not waiting for the geolocation to starts displaying the interface. Then when geolocation is done inject the models.
What url scheme should I use?
Should I still use the rest adapter form ember-data or not?
Assuming location is a property of the model you want to load, and Place is the name of your model, have you tried something like this:
App.Place.find({location: "foo"});
This would issue a request in the form:
myhost.com/places?location=foo
Hope it helps.
Ember has find() method to issue GET towards the server. You can do it with id or without.
I am looking at the official guide and I'm missing something important:
I cannot find the methods which suppose to make my life easier, what are the methods which invoke PUT/POST and DELETE?
I'm using FixtureAdapter, I want to make sure the methods for add/delete and edit, that I'm writing now, will be functional with the RESTAdapter when my server side will be completed.
The fixture adapter doesn't make any calls back to the server, so it's harder to see, but if you look in the restadapter code you can see the calls that do the put/post/delete.
updateRecord: This exsits on the adapter itself, really you should call save on a model and allow ember data to choose the updateRecord on its own. model.save()
createRecord: this should be called from the Class App.KewlKidz.createRecord({id:3, name:"me"});
deleteRecord: call this bad boy on the model. model.deleteRecord()
Rest Adapter
Ember Data Model