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

Enable remote loading of json data using addRoutes option #18

Open
narayanpai opened this issue May 12, 2015 · 3 comments
Open

Enable remote loading of json data using addRoutes option #18

narayanpai opened this issue May 12, 2015 · 3 comments

Comments

@narayanpai
Copy link

Couldn't find much documenation for handler method. Any help would be appreciated

@biril
Copy link
Owner

biril commented May 12, 2015

The handler's signature and semantics are documented as part of addRoute.

Let me know if you need help with something more specific.

@narayanpai
Copy link
Author

I'm trying to do following, since its an async call, the following code doesn't work. Is there a better way to do the following

  fauxServer.addRoutes({
    listContacts: {
      urlExp: 'api/contacts',
      httpMethod: 'GET',
      handler: function(context) {
        $.getJSON('mock\test-data.json', function(data) {
          context.data = data;
        });
      }
    }
  });

@biril
Copy link
Owner

biril commented May 12, 2015

Unfortunately, async handlers are not supported.

If you can't load the test data up front (so that you synchronously return them when the handler is invoked) I would suggest that you don't use BFS for this but rather override the relevant model's sync method to do the job. Something along the lines of

myModel.sync = function (method, model, options) {
  if (method !== 'read') {
    throw 'this will only work for GET';
  }
  return $.getJSON('mock\test-data.json', function (data) {
    options.success(data);
  });
};

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

2 participants