4

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

4

7 回答 7

10

看起来这是在@cyclomarc 回答后不久更新的(检查公关https://github.com/emberjs/data/pull/1145)。在 ember 数据中,“url”现在是“主机”。“命名空间”剧照有效。

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

发送请求到http://google.com/api/*

Ember v1.0.0-7

Ember 数据 v1.0.0-beta.1-17

编辑:这现在记录在 TRANSITION.md 中: https ://github.com/emberjs/data/blob/master/TRANSITION.md#host-and-namespace-configuration

于 2013-09-02T02:36:30.043 回答
1

Ember-Data 1.0 beta 是对 API 的完全重写,请参阅转换指南,其中详细说明了所做的更改

过渡指南提到适配器 API 已更改,必须重新构建适配器。这可能是一个突破性的变化,关于端点定制的文档即将发布

于 2013-09-01T13:03:24.963 回答
1

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'
})
于 2013-09-04T09:21:37.970 回答
1

似乎是一种回归。PR 由 Paul Chavard 注册。见https://github.com/emberjs/data/pull/1145

同时,覆盖 buildUrl 是一种解决方案(请参阅@intuitivepixel 的答案)

于 2013-09-01T13:35:02.853 回答
1

请参阅上面的链接。

请注意,对于当前的 ember-data 测试版,您必须调用您的自定义适配器“App.ApplicationAdapter

如果您尝试“App.Adapter”,则不起作用。

希望有帮助!

于 2013-09-04T23:25:02.377 回答
0

beta1 中的 RESTAdapter 似乎有很多回归。我现在正在看它,到目前为止,我发现它不见了:

  • 命名空间/url 配置
  • camelCase 到 lower_with_underscore 属性映射
  • GET url 上的查询参数

过渡指南中没有提到上述内容(除非我完全错过了它)。

于 2013-09-01T13:08:37.737 回答
0

在查看了过渡指南之后,仍然没有提及这一点,url并且namespace已从RESTAdapter源代码内联注释中的进一步阅读中删除,但仍然可以按照问题中的说明使用它。但正如@cyclomarc 在他的评论中提到的(指的是@tchak13 所说的现在应该使用buildURL的内容),所以这就是你可以如何覆盖buildURL函数:

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;
  }
});

希望能帮助到你。

于 2013-09-01T12:48:27.690 回答