Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
  .vscode
  coverage
  dist
  package.json
  .npmignore
  README.md
  karma.conf.js
  rollup.config.js
  bitbucket-pipelines.yml
  CHANGELOG.md
  CONTRIBUTING.md
  .eslintrc.json
  .editorconfig
  .tern-project
  satin-relational-0.18.0.tgz
Size: Mime:
  README.md

About Backbone-Relational-JSON:API

Adds JSON API support to Backbone models and collections

Compatibility and Requirements

  • Babel/Browserify/ES6 Support

Adding To Your Project

  1. Ensure your computer will use npm.kinetic-vision.com as its registry.
  2. run npm install satin-relational --save to start to use! See examples below.

You should have no issues with your client-side code when switching to this library from standard Backbone or Backbone-relational models. All Backbone model calls stay the same. This only acts an an adapter and serializer between native Backbone data structures and JSON:API specifications for API responses.

Usage Examples

You must define a model type on all models that can be returned from your JSON:API.

Model Definition

// models/color-metric.js
import { Model, HasOne } from 'satin-relational';
import PixelMetricModel from './pixel-metric';

export default Model.extend({
    relations: [
        {
            key: 'pixel_metric',
            type: HasOne,
            relatedModel: PixelMetricModel
        }
    ]
}, {
    type: 'color_metrics',
    apiVersion: 'v1'
});

Model Fetching

import ColorMetricModel from 'models/color-metric';

var metricModel = ColorMetricModel.findOrCreate({ id: 1 });
metricModel.fetch({
    include: ['pixel_metrics']
});

Fetch Options

Option Type Description
include Array An array of related model types to include [ 'child_model_type', ... ]
fields Object A hash of { modelType: [ 'field', 'names' ], ... } to limit the response to
sort Array A hash of [ { attribute: 'key_name', direction: 'asc' }, ... ]

Collection Definition

// collections/color-metric.js
import { Collection } from 'satin-relational';
import ColorMetricModel from 'models/color-metric';

export default Collection.extend({
    model: ColorMetricModel
});

Collection Fetching

import ColorMetricCollection from 'collections/color-metric';

var colorMetricCollection = new ColorMetricCollection();
colorMetricCollection.fetch({
   include:['pixel_metrics']
    page: {
        offset: 10,
        limit: 5
    }
});

Fetch Options

Option Type Description
include Array An array of related model types to include [ 'child_model_type', ... ]
fields Object A hash of { modelType: [ 'field', 'names' ], ... } to limit the response to
sort Array A hash of [ { attribute: 'key_name', direction: 'asc' }, ... ]
page Object A hash of { offset: 0, limit: 0 } or { number: 0, size: 0 } depending on your server paginator setup
filter Object A hash of { modelType: { attribute: 'value', ... }, ... }

More To Come

  • Authorization Header support/JWT support
  • Unit tests

Contributing

Read more here