Ember data 1.0.0 Beta: setting endpoint RESTAdapter no longer works

I am converting a project for use with Ember Data 1.0.0 Beta 1 (just released). I have a REST adapter that listens on a specific endpoint and therefore it is necessary to configure the endpoint.

Here's how it works in Ember 0.13 data:

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

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

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

c / 192.168.0.108: 51939 URL on which webapp runs.

So it looks like setting the URL to .reopen from the RESTAdapter no longer works?

I have the same problem with other URL settings (e.g. namespace) ...

Hope someone can help.

Mark

+4
source share
7 answers

It looks like this was updated shortly after @cyclomarc's answer (check out the PR https://github.com/emberjs/data/pull/1145 ). In the ember data, "url" is now "host". The "fixed namespace" works.

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

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

Ember v1.0.0-7

Ember Data v1.0.0-beta.1-17

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

+10
source

Ember-Data 1.0 beta - complete redesign of the API, see the migration guide for details on the changes made

The migration guide mentions that the adapter API has changed and adapters will need to be rebuilt. This is most likely a violation, and the documentation will be ready to configure the endpoint.

+1
source

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

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

+1
source

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
source

Refer to the links above.

Please note that for the current beta version of ember data, you must call your user adapter "App. ApplicationAdapter ".

It does not work if you try the "App.Adapter".

Hope this helps!

+1
source

RESTAdapter at the transition guide , it is still not mentioned that url and namespace are removed from the RESTAdapter , then reading the embedded comments in the source text is still referenced, it can be used as indicated in the question. But since @cyclomarc mentioned in his comment (referring to @ tchak13 saying that buildURL should be used buildURL ), you can do this by 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 this helps.

0
source

The RESTAdapter in beta seems to have quite a few regressions. I look at it now and still see the missing:

  • Namespace / URL Configuration
  • mapping camelCase attributes to lower_with_underscore
  • GET url request parameters

Not mentioned above is mentioned in the migration guide (unless I missed it completely).

0
source

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


All Articles