Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syncer.js forces www-form-urlencoded PUT/POSTS #110

Open
argl opened this issue Aug 16, 2013 · 3 comments
Open

syncer.js forces www-form-urlencoded PUT/POSTS #110

argl opened this issue Aug 16, 2013 · 3 comments

Comments

@argl
Copy link

argl commented Aug 16, 2013

I am working with a couchdb backend and syncer.js gives me headaches when saving models. Couch really likes to be data sent as JSON, but the syncer insists on classic www-form-urlencoded.

In syncer.js the emulateJSON setting for the request is hardcoded to true. commenting these 2 lines makes everything work correctly.

function myClientSync(method, model, options) {
  var data;
  data = _.clone(options.data);
  options.url = this.getUrl(options.url, true, data);
  data = addApiParams(method, model, data);
  //options.data = data;
  //options.emulateJSON = true;
  return Backbone.sync(method, model, options);
}

Is there any way to officially change this behaviour other than patching rendr itself?

@misuba
Copy link

misuba commented Sep 13, 2013

You're gonna want to take a close look at syncer.js' getUrl and decide whether that's a thing you even need done (since you're already doing nothing here with the results of addApiParams). If you don't, it should (hopefully - I don't know your whole situation of course) be simple to skip clientSync entirely and substitute plain Backbone.sync on the client side.

I get the impression that clientSync is mostly there for the particular internal needs of Airbnb - we were in a similar situation to yours and when I realized this it really brightened my day!

@koichik
Copy link
Contributor

koichik commented Sep 14, 2013

@argl On the client-side, syncer (clientSync) doesn't talk to a backend (CouchDB) directly. Instead, it talks to the Rendr server as described below:

syncer --> Backbone.sync --> (HTTP) --> apiProxy --> dataAdapter --> (HTTP) --> backend

emulateJSON is just used between a client and Rendr server, but not between Rendr server and a backend (at least, latest version of dataAdapter in rendr-app-template, see code.).
If your CouchDB gets urlencoded request rather than JSON, can you check your own dataAdapter?

P.S.
When a Model acts on the server-side, syncer (serverSync) uses dataAdapter directly:

syncer --> dataAdapter --> (HTTP) --> backend

@lo1tuma
Copy link
Member

lo1tuma commented Feb 6, 2014

#273 should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants