Skip to content

Migrate from 1.x to 2.0

Sandro Munda edited this page Feb 26, 2016 · 1 revision

According to this issue https://github.com/SeyZ/jsonapi-serializer/issues/17 we decided to return the json result synchronously instead of a Promise. So, in a nutshell:

1.x (before)

var JSONAPISerializer = require('jsonapi-serializer');

new JSONAPISerializer('users', data, {
  topLevelLinks: { self: 'http://localhost:3000/api/users' },
  dataLinks: {
    self: function (user) {
      return 'http://localhost:3000/api/users/' + user.id
    }
  },
  attributes: ['firstName', 'lastName']
}).then(function (users) {
  // `users` here are JSON API compliant.
});

2.x (now)

var JSONAPISerializer = require('jsonapi-serializer');

var users = new JSONAPISerializer('users', data, {
  topLevelLinks: { self: 'http://localhost:3000/api/users' },
  dataLinks: {
    self: function (user) {
      return 'http://localhost:3000/api/users/' + user.id
    }
  },
  attributes: ['firstName', 'lastName']
});

// `users` here are JSON API compliant.
Clone this wiki locally