4
votes

I am converting a project for use with Ember data 1.0.0 Beta 1 (just released). I have a REST adapter listening on a specific endpoint and thus need to customize the endpoint.

This is how it worked in Ember data 0.13:

App.Adapter = DS.RESTAdapter.extend({})

DS.RESTAdapter.reopen({
  url: 'https://api.example.com'
});

In Ember data 0.13, the URL became: https://api.example.com/authors

In Ember data 1.0.0, the url becomes: http://192.168.0.108:51939/authors

with /192.168.0.108:51939 the url on which the webapp is running.

It thus looks like the url setting on .reopen of a RESTAdapter no longer works ?

I have the same problem with other customizations of the URL (such as namespace) ...

Hope somebody can help.

Marc

7
could you accept my answer? i believe it is still correctandorov

7 Answers

10
votes

Looks like this was updated soon after @cyclomarc's answer (check the PR https://github.com/emberjs/data/pull/1145). In ember data 'url' is now 'host'. 'namespace' stills works.

DS.RESTAdapter.reopen({
  host: 'http://google.com',
  namespace: 'api'
});

Sends requests to http://google.com/api/*

Ember v1.0.0-7

Ember Data v1.0.0-beta.1-17

EDIT: This is now documented in TRANSITION.md: https://github.com/emberjs/data/blob/master/TRANSITION.md#host-and-namespace-configuration

1
votes

Ember-Data 1.0 beta is a complete rewrite of the API, see the transition guide, which details the changes made

The transition guide mentions that the Adapter API has changed, and adapters will have to be rebuilt. This is likely a breaking change, and the documentation is forthcoming on the endpoint customization

1
votes

Seems to be a regression. A PR is registered by Paul Chavard. See https://github.com/emberjs/data/pull/1145

In the meantime, overriding the buildUrl is a solution (see answer from @intuitivepixel)

1
votes

https://github.com/emberjs/data/blob/master/TRANSITION.md

http://emberjs.com/guides/models/connecting-to-an-http-server/

App.ApplicationAdapter = DS.RESTAdapter.extend({
  host: 'http://api.example.com',
  namespace: 'admin'
})
1
votes

Refer to the links above.

Note that with the current ember-data beta you must call your custom adapter "App.ApplicationAdapter".

Doesn't work if you try "App.Adapter".

Hope that helps!

0
votes

It seems the RESTAdapter in beta1 has quite a few regressions. I'm looking at it now and so far I see missing:

  • namespace/url configuration
  • camelCase to lower_with_underscore attribute mapping
  • query params on GET url

Non of the above is mentioned in the transition guide (unless I completely missed it).

0
votes

Having looked into the transition guide, still no mention about that url and namespace are removed from the RESTAdapter, further reading in the source code inline comments still refer it can be used as mentioned in the question. But as @cyclomarc mentioned in his comment (referring to what @tchak13 said that one should now use buildURL), so this is how you could do it overriding the buildURL function:

App.Adapter = DS.RESTAdapter.extend({
  buildURL: function(type, id) {
    var url = "/" + Ember.String.pluralize(type.typeKey);
    if (id) { url += "/" + id; }

    return 'https://api.example.com' + url;
  }
});

Hope it helps.